FIX: SQLDescribeCol Returns Wrong Column Size in a Union Query with Parameters (308211)
The information in this article applies to:
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.5 SP1
- Microsoft Data Access Components 2.5 SP2
- Microsoft Data Access Components 2.6
- Microsoft Data Access Components 2.6 SP1
- Microsoft Data Access Components 2.7
- Microsoft ODBC Driver for SQL Server 2000 2000.80.194
- Microsoft ODBC Driver for SQL Server 2000 2000.80.380
- Microsoft ODBC Driver for SQL Server 2000 2000.81.7713.0
- Microsoft ODBC Driver for SQL Server 3.7
This article was previously published under Q308211 SYMPTOMSSQLDescribeCol returns the wrong column length if all of the following conditions are met:
- The query consists of a union of two or more SELECT statements.
- One of the WHERE clauses contains parameters.
- The first of the two unioned queries returns a constant for a column (for example, SELECT 'ABC') and the other returns a column (for example, SELECT col1).
CAUSE
The driver truncates the query for the meta data on the UNION keyword. As a result, only meta data for the first query is requested from Microsoft SQL Server. The second query is ignored. If you change the order of the queries, SQLDescribeCol returns correct data.
RESOLUTIONTo resolve this problem, obtain the latest service pack for Microsoft Data Access Components 2.6. For additional information, click the following article number to view the article in the
Microsoft Knowledge Base:
300635 INFO: How to Obtain the Latest MDAC 2.6 Service Pack
WORKAROUND
To work around this problem, follow these steps:
- Compile the query into a stored procedure that contains parameters.
- Reverse the order of the SELECT statements in the union query so that the constant field is in the latter SELECT statement.
- Call SQLBindParameter before you call SQLDescribeCol.
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Microsoft Data Access Components 2.6 Service Pack 2. NOTE: This fix does not resolve more complex queries, such as those that are described in the following article in the Microsoft Knowledge Base:
308264 BUG: SQLDescribeCol Returns Wrong Column Size in a Complex Union Query with Parameters
| Modification Type: | Minor | Last Reviewed: | 9/26/2005 |
|---|
| Keywords: | kbHotfixServer kbQFE kbbug kbfix kbmdac260sp2fix KB308211 |
|---|
|