FIX: EXECUTE Command w/ a Local Variable Can Cause Thread AV

Last reviewed: April 30, 1997
Article ID: Q132345
The information in this article applies to:
  • Microsoft SQL Server, version 6.0
BUG# NT: 10191 (6.00)

SYMPTOMS

Invalid 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.

CAUSE

The 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
   go

The 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

  • Ensure the syntax of the EXECUTE command is correct. If the command you are attempting to execute is not a stored procedure, place parenthesis around it. See "SQL Server Books Online" for the documented syntax of the EXECUTE command. Other commands may include local variables larger than char(30).
  • Use char(30) when you execute a stored procedure to guarantee object identifier length.

STATUS

Microsoft 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
Keywords : kbbug6.00 kbfix6.00.sp1 kbother SSrvWinNT
Version : 6.0
Platform : WINDOWS
Issue type : kberrmsg


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.