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
1
vote
1 answer

How to protect against a process run from xp_cmdshell remaining in KILLED/ROLLBACK state forever?

I'm using xp_cmdshell on SQL Server 2016 SP1 (soon to upgrade to a newer version) to run a couple of things, mainly a batch file that calls psftp.exe, for sending files over SFTP. Very occasionally, psftp.exe will be in the process of sending a file…
Geoff Griswald
  • 937
  • 12
  • 24
1
vote
1 answer

bcp in SQL Server

I want to use bcp in SQL Server to transfer data of a table to a text file. After that I want to truncate that table and move the transferred data from created text file to that table. I want to check status (something like error status) to…
1
vote
0 answers

BCP file name as datetime stamp

I am trying to crate a CSV export file using BCP with a the datetime stamp in the file name. Everything appears correct but I keep getting errors around the + sign. BEGIN SET NOCOUNT ON DECLARE @mydate DATETIME DECLARE @filename…
1
vote
1 answer

xp_cmdshell write file directory to a text file

how do I write my file directory to a text file? The directory I want to use is C:\ The code I have now is exec xp_cmdshell 'dir *.exe & echo > file_directory.txt';-- It's not writing to a file though. Do I need to say this... exec xp_cmdshell 'cd…
OneSneakyMofo
  • 1,305
  • 2
  • 19
  • 33
1
vote
1 answer

XP_CMDSHELL keeps getting disabled from time to time with no reason

I want to know how can i keep XP_cmdshell enabled forever. Its a local system, and I am using xp_cmdshell to generate a txt file with query results. I cant enable xp_cmdshell in the code itself because it gave me an error saying I cant activate it…
Alexandre Calvario
  • 143
  • 1
  • 1
  • 11
1
vote
1 answer

When using xp_cmdshell to run some curl command in Stored Procedure is slow, why is that?

This is my code: SET @GETCommand = 'curl --silent -X GET -u user:password -H "Content-Type: application/json" "https://jira.com/rest/api/latest/.... > "C:\Test.txt"' EXEC xp_cmdshell @GETCommand When running it outside of Stored Procedure (SP),…
1
vote
1 answer

Execute xp_cmdshell using C#

We have created a Windows Forms application to synchronize databases using merge publication and merge pull subscription. We have created publication and subscription successfully. Now We want to start synchronize data. For that we want to execute…
1
vote
1 answer

Does MySql support extproc?

I just want to know if MySql supports low-level database functions such as xp_cmdshell and extproc. I know xp_cmdshell is not supported for MySql due to security policies but what about extproc?
1
vote
1 answer

xp_cmdshell a network error has occurred

I am moving a SQL database from my C:\ to a Server and I'm a little new at this. I use Openrowset and Opendatasource to get data from Excel, Access, and CSV files but now it only works with a fixed drive (C:\ or E:). I am trying to use xp_CmdShell…
anonymous
  • 113
  • 13
1
vote
2 answers

Creation of stored procedures in SQL Server

I'm working on a fairly large application in which a database schema (tables, stored procedures, etc) is created by running a SQL script. The script is invoked from a stored procedure via xp_cmdshell like this. CREATE PROC CreateNewScheme AS BEGIN …
1
vote
1 answer

Calling stored procedure from web application on UNIX throwing error on xp_cmdshell

Hey all, I'm pulling my hair out on this one. I've checked all my permissions, on both the database server (SQL Server 2000) and the file system to ensure that what I am trying to do should be possible. Here's the situation: I have a Java EE web…
karlgrz
  • 14,485
  • 12
  • 47
  • 58
1
vote
1 answer

xp_cmdshell and echo in sql server trigger

I am trying to export some data and fixed characters from a SQL Server table to a text file. I need a large number of such lines exported to the text file so I am trying to cut down on DECLARing and SETting a large number of command variables by…
Jay
  • 13
  • 5
1
vote
1 answer

BCP hang when executed through trigger

When I executes this command, it works! DECLARE @CMD NVARCHAR(1000) SET @CMD = 'cd.. && "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\bcp.exe" "SELECT TOP 1 CODE FROM[TABLE] WITH (NOLOCK) ORDER BY ID DESC" queryout…
1
vote
1 answer

Which account is used when executing xp_cmdshell 'wmic ... "java -jar ..."'

I have a jar file that I want to run as a step in an SQL Job. However, the jar file has to run on machineA but the SQL job is schedule on serverA. To make this possible, in serverA's SQL job, I use xp_cmdshell to issue a wmic command to the…
Krish
  • 319
  • 4
  • 19
1
vote
2 answers

excaping characters to run xp_cmdshell

I know that I need to escape the @cmd var to run: declare @cmd 'xp_cmdshell ''echo Mary|Warrior > c:\test.txt''' exec (@cmd) because the character '|' would fail when running the command. So, previous running I set: set @cmd = replace(@cmd, '|',…
user3770963
  • 47
  • 1
  • 7