FIX: EXECUTE Command w/ a Local Variable Can Cause Thread AVLast reviewed: April 30, 1997Article ID: Q132345  | 
	
	
 
 
The information in this article applies to:
 
 SYMPTOMSInvalid syntax when you build an EXECUTE statement from a local variable can cause a thread access violation (AV). The access violation can be generated when Microsoft SQL Server version 6.0 attempts to resolve a stored procedure name that was built in a declared variable. SQL Server generates a thread access violation and aborts the connection. 
 CAUSEThe error occurs when the EXECUTE statement treats an oversized buffer (more then 30 characters) as a stored procedure name instead of as a specific Transact-SQL command due to the use of invalid syntax for the EXECUTE statement itself. For example: 
 use pubs go declare @strCommand char(128) select @strCommand = 'select * from authors' execute @strCommand goThe behavior can be altered by changing the variable declarations. 
 DECLARATION      BEHAVIOR
-----------      ---------
varchar(xxx)     Successful completion of command, or appropriate error
                 returned:
                 'Unable to find stored procedure 'select * from authors'
char(30)         Successful completion of command, or appropriate error
                 returned:
                 'Unable to find stored procedure 'select * from authors'
char(128)        Thread access violation.
The behavior does not change if you use a valid stored procedure name, such
as sp_who; char(128)continues to cause an access violation, and char(30)
continues to execute successfully. This is because char(30) is a valid
length for an object identifier.
 WORKAROUND
 STATUSMicrosoft has confirmed this to be a problem in Microsoft SQL Server version 6.0. This problem was corrected in Service Pack 1 for SQL Server version 6.0. For more information, contact your primary support provider. 
  | 
	
	Additional query words: sql6 Windows NT 
 © 1998 Microsoft Corporation. All rights reserved. Terms of Use.  |