BUG: Access Violation with xp_cmdshell Returning Data into a Table with More Columns Than Returned

Article translations Article translations
Article ID: 264058 - View products that this article applies to.
This article was previously published under Q264058
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 57977 (SQLBUG_70)
Expand all | Collapse all

Symptoms

When an xp_cmdshell extended stored procedure query returns information to a table, if the table is declared with more columns than xp_cmdshell returns, the client receives an Access Violation (AV). The following script:
DECLARE @FileName VARCHAR(100), @DirCmd VARCHAR(150)
SET @FileName = 'c:\pagefile.sys'
SET @DirCmd = 'dir ' + @FileName
CREATE TABLE #DirFile (Diroutput text, col2 text)
INSERT #DirFile  EXEC master.dbo.xp_cmdshell @DirCmd
				
returns the following error message:
Server: Msg 213, Level 16, State 7, Procedure xp_cmdshell, Line 5
Insert Error: Column name or number of supplied values does not match table definition.
ODBC: Msg 0, Level 20, State 1
Stored function 'xp_cmdshell' in the library 'xpsql70.dll' generated an
access violation. SQL Server is terminating process 13.

Workaround

Declare the table with the correct number of columns. In the preceding example, if you remove col2, the query works correctly.

Status

Microsoft has confirmed this to be a problem in SQL Server 7.0.

Properties

Article ID: 264058 - Last Review: November 2, 2013 - Revision: 2.0
Applies to
  • Microsoft SQL Server 7.0 Standard Edition
Keywords: 
kbnosurvey kbarchive kbbug KB264058

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com