The SQLDescribeCol command returns metadata for the last statement from the batch when executed on a prepared batch of SQL statements (884315)



The information in this article applies to:

  • Microsoft ODBC Driver for SQL Server 2.5

SYMPTOMS

You receive the metadata for the last SQL statement from a batch of SQL statements when you run the SQLDescribeCol command on the prepared batch of SQL statements in the ODBC Test tool.

CAUSE

The ODBC driver overwrites the column information in the buffer. Therefore, the metadata is retrieved only for the last SQL statement from a prepared batch of SQL statements.

RESOLUTION

To resolve this problem, follow these steps to execute the prepared batch of SQL statements before running the SQLDescribeCol command.
  1. Start ODBC Test.
  2. Prepare the batch statement.
  3. On the Stmt menu, click SQLExecute.
  4. In the SQLExecute dialog box, click OK.
  5. On the Results menu, click SQLDescribeCol.
  6. In the SQLDescribeCol dialog box, click OK to see the result of first statement in the prepared batch statement.
  7. On the Results menu, click SQLMoreResults.
  8. In the SQLMoreResults dialog box, click OK.
  9. On the Results menu, click SQLDescribeCol.
  10. In the SQLDescribeCol dialog box, click OK to see the next result.

MORE INFORMATION

The problem exists in version 2000.85.1022 of the SQLSRV32.dll file. The SQLSRV32.dll file is the Microsoft SQL Server ODBC driver. Version 3.7 of the SQLSRV32.dll file shows the correct behavior when you run the SQLDescribeCol command.

Steps to reproduce the behavior

  1. Create a new SQL Server database and add new tables to it.
    1. Open SQL Query Analyzer.
    2. Run the following scripts in SQL Query Analyzer:
      Create database Test
      go
    3. Run the following code in SQL Query Analyzer:
      use Test
      go
      drop table TSTSIMPLE
      go
      create table TSTSIMPLE( clef1 int, champ char(20))  
      insert into TSTSIMPLE values( 0, 'Microsoft SQL Server')
      insert into TSTSIMPLE values( 1, 'Un')
      insert into TSTSIMPLE values( 2, 'Deux')
      go 
      drop table TSTDATE 
      go  
      create table TSTDATE(clef2 datetime, champ varchar(20)) 
      go 
      insert into TSTDATE values(getdate(), 'I was here')
      go 
      select * from TSTSIMPLE 
      go
      select * from TSTDATE 
      go
  2. Create a Data Source Name (DSN).
    1. In Control Panel, double-click Administrative Tools.
    2. Double-click Data Sources (ODBC).
    3. In the ODBC Data Source Administrator dialog box, click Add.
    4. In the Create New Data Source dialog box, click SQL Server in the Select a driver for which you want to set up a data source list, and then click Finish.
    5. In the Create a New Data Source to SQL Server dialog box, type <name> in the Name box.

      Note <name> is a placeholder for the DSN name that you want to create.
    6. In the Server box, type <ServerAddress>, and then click Next.

      Note <ServerAddress> is a placeholder for the address of the SQL Server where you have created the database in step 1.
    7. Click Next.

      Note If you are using SQL Server authentication, type your username and your password in the LoginID and Password boxes, and then click Next.
    8. Click to select the Change the default database to check box, select Test, and then click Next.
    9. Click Finish. The ODBC Microsoft SQL Server Setup dialog box appears.
    10. Click OK to close the ODBC Data Source Administrator dialog box.
  3. Run the ODBC Test tool.
    1. Start the ODBC Test tool.

      Note You can run the ODBC Test tool by running the Odbcte32.exe file on your computer. The ODBC Test tool is also available in the Microsoft Data Access (MDAC) 2.8 Software Development Kit (SDK). To download the SDK, visit the following Microsoft Web site:
    2. On the Conn menu, click Full Connect. The Full Connect dialog box appears.
    3. In the Data Source box, select or type the data source name that you created in the "Create a Data Source Name (DSN)" section, and then click OK.
    4. After you have successfully connected to the database, paste the following code in the Input window of the ODBC Test tool:
      select * from TSTSIMPLE select * from TSTDATE
    5. On the Stmt menu, click SQLPrepare.
    6. In the SQLPrepare dialog box, click OK.
    7. On the Results menu, click SQLDescribeCol.
    8. In the SQLDescribeCol dialog box, click OK. You notice the behavior that is mentioned in the "Symptoms" section.
The SQL batch prepare statement only shows the results of the second SQL statement. It does not show the results of the first SQL batch prepare statement.

REFERENCES

For more information about the ODBC Test tool, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MajorLast Reviewed:9/9/2004
Keywords:kbServer kbScript kbInput kbDLL kbDatabase kbtshoot kbprb KB884315 kbAudDeveloper