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



The information in this article applies to:

  • Microsoft SQL Server 7.0

This article was previously published under Q264058
BUG #: 57977 (SQLBUG_70)

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.

Modification Type:MajorLast Reviewed:10/16/2002
Keywords:kbBug KB264058