PRB: Error When You Create SQL Server TEMP Tables Using Remote Data Objects (RDO) (280134)
The information in this article applies to:
- Microsoft Visual Basic Enterprise Edition for Windows 4.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0 SP3
- Microsoft Visual Basic Enterprise Edition for Windows 6.0 SP4
- Microsoft SQL Server 6.5
- Microsoft SQL Server 6.5 Service Pack 1 and later
- Microsoft SQL Server 7.0
- Microsoft SQL Server 7.0 Service Pack 1
- Microsoft SQL Server 7.0 Service Pack 2
- Microsoft SQL Server 2000 (all editions)
This article was previously published under Q280134 SYMPTOMS When you create a SQL Server local temporary table using
the rdoConnection object by calling its .Execute method with default parameters, and then attempt to access the
table after the Remote Data Objects (RDO) method has run, you may receive one
of the following error messages: Run-time error '40002':
37000:[Microsoft][ODBC SQL Server Driver][SQL Server] Statement(s)could not be
prepared Run-time error '40002':
S0002:[Microsoft][ODBC SQL Server Driver][SQL Server] Invalid Object Name
'#<Name of the temporary table>' CAUSE The creation and use of temporary database tables to
facilitate the storage and manipulation of volatile intermediate data is a
common programming practice. The default behavior of the SQL Server Open
Database Connectivity (ODBC) driver is to create and use temporary stored
procedures to run prepared statements. The .Execute method of the rdoConnection object uses the SQLPrepare() and SQLExecute() ODBC application programming interface (API) calls by default to
run a SQL statement as a prepared statement. Temporary tables that are created
by a stored procedure are automatically dropped when the procedure completes
execution. As a result, when you attempt to access a SQL Server temporary table
that was created by calling the .Execute method of an rdoConnection object with default parameters, in subsequent statements you
receive one of the error messages specified in the "Symptoms" section.
RESOLUTION To resolve this problem, use one of the following
workarounds:
- Specify rdExecDirect as the Options parameter of the .Execute method of the rdoConnection object to bypass the creation of a temporary stored procedure,
and force the usage of the SQLExecDirect() ODBC API function to run the SQL query that creates the temporary
table.
- If you use a SQL Server version 6.5 database, you can turn
off the option to use temporary stored procedures to run prepared statements in
the ODBC data source name (DSN) configuration properties. However, you cannot
turn off this property when you create an ODBC DSN to connect to a SQL Server
7.0 or SQL Server 2000 database. It is turned on by default and the check box
to control its setting in the DSN configuration dialog box is
dimmed.
- Use an rdoQuery object to run the SQL query that creates the temporary table
after it sets its Prepared property to True.
Modification Type: | Major | Last Reviewed: | 6/28/2004 |
---|
Keywords: | kbprb kbRDO kbRDO100 KB280134 |
---|
|