The information in this article applies to:
SYMPTOMSWhen attempting to create a temporary table(for example, #temp) with ODBCdirect, you receive no indication that the temporary table was created and no errors are reported. CAUSEThe temporary table is created but as a result of its scope, the table appears not to be created. The default execution option for Connection and QueryDef statements is to run as a prepared statement. When the statement is executed as a prepared statement, the SQLPrepare ODBC API function is called and a temporary stored procedure is created in which the statement executes. As a result of the temporary stored procedure execution, the temporary table is destroyed as the stored procedure terminates. Thus, the scope of local temporary tables is the transaction space or stored procedure in which they were created. SQLServer Books Online contains a detailed discussion of the scopy of local and global temporary tables. To reproduce the problem, refer to the code sample contained in the MORE INFORMATION section of this article. RESOLUTION
If you need to refer to a temporary table created with ODBCdirect, send the
SQL statement in one transaction statement or use the <dbExecDirect> option
with ODBCDirect Connection and QueryDef objects. For example:
This example demonstrates that the #temp table is created during step 4 but pausing/stopping the code at any point does not reveal that fact. The SQL statement is being executed and the connection is closed immediately, so you do not see the details within ISQL_W or Visual Basic. NOTE: The <DROP TABLE> statement deletes the table from the database so you may run the example again. To refer to the temporary table at some other point in the code, use the <dbExecDirect> option with the Connection or QueryDef object as in the following example. Follow steps 1 through 3 as in the previous example. Then paste the following code in the <Form-Load> event and run the project:
You should see rows returned in the results windows. This demonstrates that
the temporary table was created and its scope was not limited to a prepared
statement (temporary stored procedure) but the database connection.
STATUSThis behavior is by design. MORE INFORMATIONSteps to Reproduce Behavior
REFERENCESSQLServer Books Online Visual Basic Books Online, "ODBCDirect Prepared" Additional query words: kbDSupport kbdse kbvbp600 kbvbp500 kbDAO350 kbDAO kbSQLServ kbDatabase
Keywords : kbGrpVBDB |
Last Reviewed: January 5, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |