PRB: Meta Data ODBC Calls Fail on SQL Server Queries with Parameter Markers in Sub-Selects (321842)



The information in this article applies to:

  • Microsoft ODBC Driver for SQL Server 1.0
  • Microsoft ODBC Driver for SQL Server 2.0
  • Microsoft ODBC Driver for SQL Server 2.5
  • Microsoft ODBC Driver for SQL Server 2.65
  • Microsoft ODBC Driver for SQL Server 2.65.0212
  • Microsoft ODBC Driver for SQL Server 2000.80.194
  • Microsoft ODBC Driver for SQL Server 3.0
  • Microsoft ODBC Driver for SQL Server 3.5
  • Microsoft ODBC Driver for SQL Server 3.6
  • Microsoft ODBC Driver for SQL Server 3.7

This article was previously published under Q321842

SYMPTOMS

ODBC application programming interface (API) calls such as SQLDescribeCol, SQLDescribeParam, and SQLNumResultCols, that retrieve meta data, fail when an application tries to use the calls with Microsoft ODBC Driver for SQL Server on parameters that are part of the subqueries.

CAUSE

The driver does not retrieve information for parameters that are not bound in subqueries.

STATUS

This behavior is by design.

MORE INFORMATION

SQLNumResultCols returns an incorrect column count, and SQLDescribeCol returns an error similar to the following:
[Microsoft][ODBC SQL Server Driver]Prepared statement is not a cursor-specification
If the parameters have been bound by the application through the SQLBindParameter API, the driver uses that information and the meta data calls do not fail.

To reproduce this behavior from the ODBC Test tool, follow these steps:
  1. Connect to the NorthWind database in SQL Server.
  2. Call SQLPrepare on the following line of code:
    select T1.EmployeeID as c1 from (select * from EMPLOYEES where EMPLOYEES.EmployeeID   = ?) T1
    					
Note that SQLNumResultCols returns 0 instead of 1. If SQLBindParameter was called before SQLNumResultCols, the correct column count is retrieved.

REFERENCES


Modification Type:MajorLast Reviewed:9/30/2003
Keywords:kbDatabase kbprb kbProgramming KB321842