You are currently offline, waiting for your internet to reconnect

FIX: Access violation when you execute a stored procedure that uses a cursor on a table variable in SQL Server

Symptoms
Assume that you create a stored procedure that uses a cursor on a table variable in Microsoft SQL Server 2012 or SQL Server 2014. Additionally, the stored procedure updates the table by using a WHERE CURRENT OF statement together with the cursor.

For example, your stored procedure may resemble the following:
CREATE PROCEDURE dbo.usp_TestSP AS  BEGIN  DECLARE @TableVar TABLE (SomeInt INT NULL) INSERT @TableVar VALUES (NULL)  DECLARE @curInt INT, @newInt INT SET @newInt = 1  DECLARE ccc CURSOR LOCAL FOR SELECT SomeInt FROM @TableVar WHERE SomeInt IS NULL  OPEN ccc  FETCH NEXT FROM ccc INTO @curInt UPDATE @TableVar SET SomeInt = @newInt WHERE CURRENT OF cccCLOSE ccc  SELECT * FROM @TableVar END 

When you execute your stored procedure by using the sp_refreshsqlmodule system stored procedure, an access violation may occur, and you may receive error messages that resemble the following:
Msg 596, Level 21, State 1Cannot continue the execution because the session is in the kill state.Msg 0, Level 20, State 0A severe error occurred on the current command. The results, if any, should be discarded.

In this situation, errors that resemble the following are also written to the SQL Server error logs:
date time.730 spid51 SqlDumpExceptionHandler: Process 51 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process.
date time.730 spid51 * *******************************************************************************
date time.730 spid51 *
date time.730 spid51 * BEGIN STACK DUMP:
date time.730 spid51 * date time spid 51
date time.730 spid51 *
date time.730 spid51 *
date time.730 spid51 * Exception Address = 00007FFC270236D5 Module(sqllang+00000000005036D5)
date time.730 spid51 * Exception Code = c0000005 EXCEPTION_ACCESS_VIOLATION
date time.730 spid51 * Access Violation occurred reading address 0000006F00620074
date time.730 spid51 * Input Buffer 136 bytes -
date time.730 spid51 * EXECUTE sp_refreshsqlmodule N'[dbo].[usp_TestSP]'
date time.730 spid51 *
date time.730 spid51 *

Resolution

Cumulative update information

This issue is fixed in the following updates:
Recommendation: Install the latest cumulative update for SQL Server

Each new cumulative update for SQL Server contains all the hotfixes and all the security fixes that were included with the previous cumulative update. Check out the latest cumulative updates for SQL Server:
Status
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
References
Learn about the terminology that Microsoft uses to describe software updates.
Properties

Article ID: 3138930 - Last Review: 05/31/2016 06:48:00 - Revision: 5.0

Microsoft SQL Server 2012 Service Pack 3, Microsoft SQL Server 2012 Service Pack 2, Microsoft SQL Server 2014 Service Pack 1, Microsoft SQL Server 2014 Developer, Microsoft SQL Server 2014 Enterprise, Microsoft SQL Server 2014 Standard

  • kbqfe kbfix kbexpertiseinter kbsurveynew KB3138930
Feedback
dy>