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

How to fix the killed/rollback state issue

When I was running some cmd through xp_cmdshell in sql server it tooks long time to execute.So I have killed the session.But it stucks in KILLED/ROLLBACK state for long time.Its a standalone production server.I cant restart this server.Is this a…
SujithTee
  • 125
  • 2
  • 3
  • 12
2
votes
1 answer

Executing a SSIS package that references mso.dll with DTEXEC

Apologies if this has been answered, but I've not been able to find an answer that solves my issue. I have a SSIS package that has a script task which references: C:\Program Files (x86)\Common Files\microsoft shared\OFFICE16\MSO.DLL. When executed…
Ian Mitchell
  • 83
  • 1
  • 7
2
votes
2 answers

How do I resolve this "Access is denied" error which occurs when using xp_cmdshell in Microsoft SQL?

This is my entire routine: Declare @AttFileType as char(5), @HQCo as int, @FormName as Varchar(15), @KeyID as VarChar(10), @UniqueID as uniqueidentifier, @FilePath as Varchar(100), @StringCommand as Varchar(200) Declare @AttID as int DECLARE…
Joshua Bryant
  • 123
  • 2
  • 10
2
votes
2 answers

How to use path having more than 128 character in 'xp_cmdshell' DIR command

I am trying to get list of files in a directory using SQL Server path having more than 128 character. It isn't working. DECLARE @FilePath varchar(256)='D:\...',--Path with a length more than 128 char @SourceFiles…
Husen
  • 1,541
  • 10
  • 14
2
votes
1 answer

How to map network drive in SQL query without using XP_CMDSHELL

Looking to just map a network drive with a different AD account in a SQL query. XP_CMDSHELL is disabled in our environment. I could technically turn it on, then "net use" the drive, and turn it off again in a query, but was looking for a cleaner…
C-COOP
  • 123
  • 1
  • 3
  • 12
2
votes
0 answers

Any performance hit by xp_cmdshell repeatedly enable and disable in a stored procedure?

I am using some dos commands to do file operations & bcp command in my sql server stored procedure. So I am setting xp_cmdshell on and off many times. I am doing this multiple times because, if I just enable once at the start of SP and disables at…
AnandPhadke
  • 13,160
  • 5
  • 26
  • 33
2
votes
2 answers

BCP Error - SQLState 3700, Native Error = 102

Here is my BCPCommand, the rest of the query is tested and working fine, I have also tested the results in the BCP Query and is also in order DECLARE @OutputFile VARCHAR(100) , @FilePath VARCHAR(100) , @bcpCommand…
user3490224
  • 21
  • 1
  • 2
2
votes
1 answer

What else I can use than xp_cmdshell

The problem I have is that we can't use the xp_cmdshell in the productive envirement. We don't have the permission for it. But what else can I use instead of xp_cmdshell for creating a file on a different server? SELECT @path = RTRIM(sys_value) FROM…
loonybin
  • 21
  • 2
2
votes
1 answer

How do I escape the "&" symbol in Sql server

I have to execute the following code in query editor Exec xp_cmdshell 'sqlps -command "$http=New-Object system.Net.WebClient;$http.uploadString(\"http://192.168.2.3:8080/ThermalMap/DBTest.jsp\",\"param1=somevalue & param2=thriu\")"' It gives me…
niren
  • 2,693
  • 8
  • 34
  • 58
2
votes
1 answer

Returning Output Paramters or Variables From SSIS Script Task / Script Component

Is it possible to return output parameters from a SSIS "Script Task" that has been called by a stored procedure using xp_cmdshell? All the samples I have found so far show how to assign values to dts package variables etc; and show them via a…
user1011144
  • 193
  • 2
  • 4
  • 13
2
votes
2 answers

SQL xp_cmdshell copy files between servers

I am trying to move all .zip in a specific folder to another folder. the source folder is located on another server, currently i am using EXECUTE xp_cmdshell 'copy \\server1\e$\ETL\*.zip \\server2\e$\ETL\' GO Which is working if I am logged into…
JPVoogt
  • 528
  • 5
  • 13
  • 25
2
votes
3 answers

xp_cmdshell Native Error 208, BCP in SQL Server 2008 R2

I've been trying to work on taking the result of a large and multiply-joined SELECT statement, and email the query result as a CVS file. I have the query correct and the emailing down, but I'm having trouble automating the export of the result as a…
Mister R2
  • 861
  • 5
  • 12
  • 22
2
votes
4 answers

Echo literal string?

I have an SQL procedure that calls the command shell to write an SQL dump to a file. Take this redacted file for example: VALUES( @SomeVar ,1 ) The procedure calls: echo VALUES(>> C:\somefile.sql echo @SomeVar>> C:\somefile.sql echo ,1>>…
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
2
votes
2 answers

T-SQL FTP using xp_cmdshell

I am using the below code snippet to FTP simple text files from a Windows Server 2003 / SQL Server 2005 database to a BULL FTP site and am getting some corruption on the BULL end. select @cmd = 'ftp -s:' + @workdir + @workfilename exec…
Phil Murray
  • 6,396
  • 9
  • 45
  • 95
2
votes
2 answers

BCP Export Automatically Converts Empty Strings to NUL

All, in this post xp_cmdshell Query Length Too Large I managed to obtain a fix for a problem I was having with the query size limit using xp_cmdshell. The reason I was writing such a long query was to attempt to get around another problem, the fact…
MoonKnight
  • 23,214
  • 40
  • 145
  • 277
1 2
3
17 18