Questions tagged [xp-cmdshell]

an extended stored procedure provided by SQL Server, which launches a Windows command shell to run a specified command. Not for general questions about cmd.exe or batch scripting; not related to Windows XP.

The xp_cmdshell extended stored procedure runs the command string given and returns any output as rows of text. The documentation (for SQL Server 2012) can be found here.

For security reasons, xp_cmdshell is disabled by default in recent versions of SQL Server.

264 questions
2
votes
3 answers

Write to file with xp_cmdshell in UTF-8

I am creating files with xp_cmdshell like this: SELECT @command = 'echo ' + @fileContent + ' > e:\out\' + @fileName + '.csv' exec master.dbo.xp_cmdshell 'mkdir "e:\out\"' exec master..xp_cmdshell @command The problem is that the file contents is…
no9
  • 6,424
  • 25
  • 76
  • 115
2
votes
1 answer

Get file contents via xp_cmdshell

Is there way to get file from windows xp command prompt? I tried to run xp_cmdshell 'type [path to file]' but then when i insert theese data into other file and renaming it to file.exe (that is executable) it does not work. Any suggestions how to…
seeker
  • 3,255
  • 7
  • 36
  • 68
2
votes
1 answer

SQL Hangs on FTP Command but works off Command Line

SQL hangs on this command: EXEC master..xp_cmdshell 'ftp -s:C:\FTP\connect' But doesn't hang on any other command I've tried using xp_cmdshell like echo open get and it works just fine, so I know the permissions for SQL Server to the Folder…
Control Freak
  • 12,965
  • 30
  • 94
  • 145
1
vote
1 answer

SQL Server 2000 xp_cmdshell

Using SQL Server 2000 I am trying to use this command in Query Analyzer xp_cmdshell 'del c:\delete-me-file.txt' and I'm getting this error: Server: Msg 2812, Level 16, State 62, Line 1 Could not find stored procedure 'xp_cmdshell'. Basically I…
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79
1
vote
3 answers

permission was denied on the object xp_cmdshell

I am getting Execute permission was denied on the object 'xp_cmdshell'. Here's the situation, I have a stored procedure called ExportFile. I am calling the stored procedure via SqlCommand from a web application from a Virtual PC.. during the…
Sharles Phirans
  • 93
  • 2
  • 3
  • 12
1
vote
1 answer

Can a SSIS package called using xp_cmdshell enlist in a SQL Server transaction?

I have a very basic SSIS package with one data flow task (from an OLE DB Source to a Flat File). The TransactionOption property is set to Required and I have tried the IsolationLevel option set to ReadCommitted, ReadUncommitted and…
Stuart Whiteford
  • 521
  • 7
  • 22
1
vote
0 answers

Trying to delete folder contents using SQL Server 2008 R2

I am executing xp_cmdshell from the SQL query editor to delete a file in a folder but getting a two rows as result; the first row contains a message "The system cannot find the file specified." and second row contains "NULL" I have tried following…
Ajendra Prasad
  • 111
  • 1
  • 2
  • 7
1
vote
0 answers

Running Python Scripts on Azure SQL Databases using Elastic Job Agent

In the past, my go-to approach for ETL jobs has been writing Python scripts (as Python, unlike many other dedicated ETL tools, brings the full power, rich libraries and customisability a programming language), and then execute these scripts using…
ImranAli
  • 166
  • 1
  • 8
1
vote
2 answers

How to run a Stored Procedure as Sysadmin?

I don't want to grant the user Sysadmin role. Is there any way to run a specific stored procedure as Sysadmin or as a user that is sysadmin? The stored procedure is in MSSQL 2005 and has xp_cmdshell Below is the code: ALTER PROCEDURE…
Bruno
  • 6,211
  • 16
  • 69
  • 104
1
vote
1 answer

Console app doesn't print when executing with xp_cmdshell under sql server agent proxy

I have a requirement to automatically print an ssrs report to a specific printer on the network whenever a new row is inserted into a database table. There is a trigger on the database table which uses xp_cmdshell to call a console application…
Ryan
  • 185
  • 1
  • 1
  • 7
1
vote
1 answer

How to append text file from sql without adding a new line

I'm currently using EXEC xp_cmdshell 'ECHO Hello > c:\file.txt' EXEC xp_cmdshell 'ECHO World >> c:\file.txt' To create and append text files from sql server. I get Hello World as the result. How can I using separate commands add both 'Hello' and…
Tomas
  • 181
  • 2
  • 10
1
vote
0 answers

Not able to enable xp_cmdshell via Openquery() in MSSQL

I have DB Links access from Instance 1 -> Instance 2. I can enable/disable xp_cmdshell in Instance 1 by directly executing the SQL query. But when I try with Openquery() I cannot enable it. I have sysadmin privilege in both Instances. I got no…
melvinjose
  • 385
  • 1
  • 3
  • 9
1
vote
1 answer

alternative to xp_cmdshell bcp?

Is there an alternative to xp_cmdshell BCP to write to a file from MSSQL? Some context: This is to be built into a stored procedure called by an external program. I do not have the luxury to work through executable files, export functions of ssms,…
Maarten H
  • 37
  • 5
1
vote
0 answers

Copy one file to another folder with same filename with xp_cmdshell

I have one csv file (pipe separated).I want to remove very first line of that CSV and at the same time,I have to move same file with same filename into another folder. After that,I have to insert that CSV into SQL table.I know,I have to use "Bulk…
Nik
  • 11
  • 1
1
vote
0 answers

File Type on xp_cmdshell queryout

I have a client who generates some csv for me with xp_cmdshell. The problem is that those files doesn't have the mymetype set correctly, because my application (and other mymetype checkers) says that the file is "application/octet-stream", and not…
lopandpe
  • 491
  • 1
  • 5
  • 10