Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xp_CMDShell

Status
Not open for further replies.

andyc209

IS-IT--Management
Dec 7, 2004
98
GB
tried creating and editing CSV files with data from SQL

on another thread i have tried BCP but it has had problems so tried another method.

I am copying a template CSV file, using Openrowset and then running a Batch file to remove the headers for import into another program

EXEC sp_configure 'show advanced option', '1';
RECONFIGURE;
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
DECLARE @FILENAME AS VARCHAR(255)
SET @FILENAME = 'COPY /Y D:\pensions\pensions.csv /B D:\pensions\pensionsexport.csv'
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
EXEC master..xp_cmdshell @FILENAME

INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0','Text;Database=D:\pensions\;HDR=NO;FMT=Delimited','SELECT * FROM [pensionsexport.csv]')
SELECT company, address, postcode FROM tbl_ifa

EXEC master..xp_CMDShell 'D:\pensions\remove.bat'

The first two parts work fine but when i run the xp.CMSShell for the batch file i get access denied. Strangely the first part which also contains xpcmdshell works fine so why can it not work on the batch file which is in the same folder
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top