FIX: Busy connections leave cursors open after call to SQLFreeStmt or SQLCloseCursor (253010)
The information in this article applies to:
- Microsoft ODBC Driver for SQL Server 3.6
- Microsoft ODBC Driver for SQL Server 3.7
- Microsoft Data Access Components 2.1
- Microsoft Data Access Components 2.1 (GA)
- Microsoft Data Access Components 2.1 SP1
- Microsoft Data Access Components 2.1 SP2
- Microsoft Data Access Components 2.5
This article was previously published under Q253010 SYMPTOMS
When using the Microsoft SQL Server ODBC driver (sqlsrv32.dll) in a manner that permits multiple concurrent statement handles on a single connection, a busy connection may leave cursors open in the SQL Server database with no warnings or notifications to the user. This happens primarily under circumstances where one or more of the statement handles are working in firehose (Forward-Only, Read-Only cursor) mode.
This can have two rather serious side effects. The first side effect is that cursors can be left open on the database server that consumes memory and may leave locks open against records. The second side effect is that subsequent attempts to execute statements on the non-firehose ODBC statement handles may generate the following error for no apparent reason:
SQLState: 24000
[Microsoft][ODBC SQL Server Driver]Invalid cursor state
This behavior occurs with the sqlsrv32.dll driver versions 3.70.0690 (Microsoft Data Access Components [MDAC] 2.1 SP2) and earlier, and with sqlsrv32.dll driver version 3.70.820 (MDAC 2.5/Windows 2000).
CAUSE
When the SQL Server ODBC driver is busy with a firehose-mode operation, no other activity can occur on the connection until the operation is complete. This includes the sp_cursorclose calls the driver issues when calling SQLFreeStmt or SQLCloseCursor.
When the driver fails to close a cursor, SQLFreeStmt and SQLCloseCursor both return SQL_SUCCESS, no errors are posted to ODBC, and no indication of the failure is available to the application or user. However, the cursor remains open in SQL Server and the statement handle still has a cursor identifier associated with it.
WORKAROUND
You can use these steps to work around the behavior:
- Execute all firehose operations on their own connection.
- Make sure all results from firehose operations are completed before closing cursors.NOTE: In a multithreaded environment, this will frequently not be possible.
- Do not use firehose operations. Instead, set the properties of all statement handles so that cursors are generated. This may include setting rowset size to something greater than one, setting SQL_ATTR_CURSOR_TYPE to something other than SQL_CURSOR_FORWARD_ONLY, and/or setting SQL_ATTR_CONCURRENCY to something other than SQL_CONCUR_READ_ONLY.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This problem was corrected in MDAC 2.6.
This problem has been corrected in U.S. Service Pack 3 for Microsoft SQL Server version 7.0. For information about how to download and install the latest SQL Server Service Pack, see the following Microsoft Web site at:
For more information, contact your primary support provider.
Modification Type: | Major | Last Reviewed: | 8/7/2006 |
---|
Keywords: | kbHotfixServer kbbug kbfix kbMDAC210SP2fix kbMDAC260fix kbMDACNoSweep kbQFE KB253010 |
---|
|