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

Access denied SSIS w/ Parameters via xp_cmdshell

I have searched up and down for a solution and cannot find anything that helps. Everything that I have tried doesnt seem to work. I have two database. I cannot modify Database A by adding a table or anything like that. I cannot enable…
Shawn Gavett
  • 458
  • 1
  • 5
  • 12
0
votes
1 answer

Copy multiple files into one with xp_cmdshell with variable path using SQL

I've created some csv files using bcp in Sql Server 2008. Now I need to merge those files into one. It works if I define explicitly the path of the files but if I declare it it tells me that it can not find the files. declare @variable_path_file1 =…
Camilla
  • 949
  • 2
  • 14
  • 26
0
votes
1 answer

Export Result to CSV using XP_CMDSHELL

I am beginner in SQL Server. When I am trying to run code: 'EXEC xp_cmdshell 'bcp "SELECT * FROM sysfiles" queryout "D:\sysobjects.txt" -T -c -t' I am getting this error: [Microsoft][SQL Server Native Client 11.0]Unable to open BCP host data-file…
0
votes
1 answer

How to Programmatically Map Drive for SQL Server Session

How can a drive (e.g. y) be mapped in C# to a network shared location? The mapped drive needs to be known by a SQL session. This is for backing up SQL databases from a C# application to the mapped drive (e.g. y). Would like to do it programmatically…
Buck
  • 599
  • 7
  • 20
0
votes
1 answer

How to NOT SELECT the OUTPUT value from a command shell script inside a stored procedure?

I have a stored procedure which is used by an SSRS report. But I need to run this before I run the query: sys.xp_cmdshell @sqlCmd; The problem is that running this first returns the OUTPUT cell. This throws off the report because it's expecting a…
JJ.
  • 9,580
  • 37
  • 116
  • 189
0
votes
0 answers

POST from SQL Server Maintenance Plan with cURL

I'm looking to monitor various events that may occur within a SQL Server Maintenance Plan. My desired method for doing this is to have the maintenance plan do an HTTP POST with the data. After some research I think my preferred approach is to use…
0
votes
0 answers

Problems executing an .exe from a trigger in SQL Server (master..xp_cmdshell)

I have a trigger associated to a table: ALTER TRIGGER [dbo].[FECR_TRIMPRIME_RETENCIONES] ON some_table The definition is this: ALTER TRIGGER [dbo].[FECR_TRIMPRIME_RETENCIONES] ON FECR_TRETENCIONES_IC FOR UPDATE AS IF UPDATE (RET_PRINT) …
user4280469
0
votes
0 answers

xp_cmdShell is not working in SQL Server 2000

I've tried to run a console application in Server from "after insert trigger" in one of my tables in SQL Server 2000. I used the following line Declare @Seq_NO bigint ; SELECT @Seq_NO=i.Seq_No from inserted i declare @CmdSQL…
Sara N
  • 1,079
  • 5
  • 17
  • 45
0
votes
1 answer

SQl Server 2014 BCP BulkCopy remove final blank line

Please can anyone advise if there is a method which can be used to stop SQL Server's BCP bulk copy command creating a final carriage return and hence a blank line at the end of the file? I have been Googling but cannot hit on a suitable answer. The…
Dib
  • 2,001
  • 2
  • 29
  • 45
0
votes
1 answer

xp_cmdshell transport-level error

Problem: Every time I try execute the following code: master..xp_cmdshell 'whoami.exe' I get the following error: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore…
John
  • 92
  • 7
0
votes
1 answer

unable to transfer file to ftp server using xp_cmdshell

I'am using this code to transfer a file from my local system to a ftp (I have all the read and write rights for this ftp). if exists (select * from sysobjects where id = object_id(N'[dbo].[s_ftp_PutFile]') and OBJECTPROPERTY(id,…
money26
  • 1
  • 3
0
votes
1 answer

Tasklist using xp_cmdshell

I want to know how i will use the tasklist cmd that will output the imagename plus the hostname i have thus syntax but could not combine the result into one. EXEC xp_cmdshell 'tasklist /fi "imagename eq notepad.exe"'; plus hostname
Mel Cuya
  • 25
  • 8
0
votes
2 answers

SQL Server : How can I enable/reconfigure xp_cmdshell through a linked server

So I want to enable xp_cmdshell through a linked server. This is my attempt: set @execute = 'exec '+'['+@server_ip+']'+'.master..sp_configure ''xp_cmdshell'', 1;' set @reconfigure = 'exec '+'['+@server_ip+']'+ 'reconfigure' exec sp_executesql…
Claudiu Haidu
  • 817
  • 4
  • 12
  • 24
0
votes
1 answer

How to run xp_cmdshell from my app in ASP.NET MVC

In my app I'm reading data to database and then I want to start Integration Serivces to import the data into the cube. This is the command, which I use to start it from SSMS: execute master..xp_cmdshell 'dtexec /DTS "\MSDB\B_Costs" /SERVER .…
Monic
  • 726
  • 10
  • 31
0
votes
1 answer

BCP output shows NULL

I have a table that has no null value in any column. When I run the following query, query analyzer shows null: EXECUTE master.dbo.xp_cmdshell 'bcp [RxDB].dbo.[DoctorCompanyRxShare] out D:\DataUpload\DoctorCompanyRxShare.txt - -t"|"…
Mashkur
  • 171
  • 1
  • 4