This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 471233 (SQL Server 8.0)
Microsoft distributes SQL Server 2000 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the software updates that were included with the previous SQL Server 2000 software update.
When you use Transact-SQL cursor variables to perform operations that have large iterations, you may notice the following behavior:
The client that performs the operations on the computer that is running SQL Server may return out-of-memory errors that are similar to the following:
Error message 1
Msg 701: There is insufficient system memory to run this query.
Error message 2
Msg 1204: The SQL Server cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users or ask the system administrator to check the SQL Server lock and memory configuration.
Error message 3
Msg 17803: Insufficient memory available.
The response from the computer that is running SQL Server 2000 may become slower.
The DBCC FREEPROCCACHE Transact-SQL statement may not free the memory or may not clear the procedure cache. This behavior may occur even when the client is disconnected from the computer that is running SQL Server.
This behavior occurs because the resources that are used by the cursor variable are not released.
To work around this problem, you must release the resources that are allocated to the cursor variables. To do so, you must make sure of the following:
If you use a SET Transact-SQL statement to set a cursor variable, you must use a DEALLOCATE Transact-SQL statement to release the resources that are used by the cursor when the cursor is no longer required.
If you use an OPEN Transact-SQL statement to open a cursor variable, you must use a CLOSE Transact-SQL statement to release the resources that are used by the cursor when the cursor is no longer required.
Service pack information
To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
290211 How to obtain the latest SQL Server 2000 service pack
The English version of this fix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
Note Because of file dependencies, the most recent hotfix or feature that contains these files may also contain additional files.
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section of this article.
This problem was first corrected in Microsoft SQL Server 2000 Service Pack 4.
The behavior that is mentioned in the "Symptoms" section occurs when you set a cursor variable, and you then re-use the same cursor variable without releasing the resources that are used by the cursor variable. For example, consider the following stored procedure:
CREATE PROCEDURE MYPROCBEGIN DECLARE @CURSOR CURSOR SET @CURSOR = CURSOR FOR SELECT * FROM AUTHORS -- FIRST ASSIGNMENT (THIS ASSIGNMENT LEAKS WHEN A SECOND ASSIGNMENT TAKES PLACE WITHOUT DEALLOCATION) --Other Transact-SQL statements SET @CURSOR = CURSOR FOR SELECT * FROM AUTHORS -- SECOND ASSIGNMENT --Other Transact-SQL statementsEND
If you run this stored procedure, you may receive the out-of-memory error messages. To resolve the problem, you must modify the stored procedure code as follows:
CREATE PROCEDURE MYPROCBEGIN DECLARE @CURSOR CURSOR SET @CURSOR = CURSOR FOR SELECT * FROM AUTHORS -- FIRST ASSIGNMENT --Other Transact-SQL statements DEALLOCATE @CURSOR --DEALLOCATING THE CURSOR VARIABLE BEFORE A SECOND ASSIGNMENT SET @CURSOR = CURSOR FOR SELECT * FROM AUTHORS -- SECOND ASSIGNMENT --Other Transact-SQL statements DEALLOCATE @CURSOR --DEALLOCATING THE CURSOR VARIABLE THAT WAS ASSIGNED SECONDEND
For additional information about software updates, click the following article number to view the article in the Microsoft Knowledge Base:
824684 Description of the standard terminology that is used to describe Microsoft software updates
For additional information about memory related issues, click the following article numbers to view the articles in the Microsoft Knowledge Base:
810052 FIX: A memory leak occurs when cursors are opened during a connection
818095 FIX: Cursor plans are not removed from the cache when virtual memory depleted
Microsoft SQL Server 2000 Developer Edition, Microsoft SQL Server 2000 Standard Edition, Microsoft SQL Server 2000 Enterprise Edition, Microsoft SQL Server 2000 Personal Edition, Microsoft SQL Server 2000, Workgroup Edition, Microsoft SQL Server 2000 Desktop Engine (Windows), Microsoft SQL Server 2000 Enterprise Edition 64-bit