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
0 answers

When I use the ">" Greater then Character in BCP command The function does not work

I have a working Stored Procedure that Creates a file based on a SQL QUERY When I run the SP this is the result that I have NULL Starting copy... SQLState = S1000, NativeError = 0 Error = [Microsoft][ODBC Driver 13 for SQL…
Alexandre Calvario
  • 143
  • 1
  • 1
  • 11
0
votes
0 answers

MS SQL 2014: create a folder structure with xp_cmdshell using loop

I have to create a folder structure. To do so, I have written a long query which seems to me very ugly: declare @KundeVorname nvarchar(50) declare @KundeNachname nvarchar(50) declare @path nvarchar(255) select @KundeVorname=a.firstname0 from…
anastasiiia
  • 189
  • 2
  • 12
0
votes
1 answer

exec master..xp_cmdshell bcp create file only works on C:\ drive

I am trying to create a formatted text file generated via stored procedure using xp_cmdshell bcp. It works, but only on C:\ drive. When I try to create the file on E:\ drive or a share drive, I get following error: SQLState = S1000, NativeError =…
NonProgrammer
  • 1,337
  • 2
  • 23
  • 53
0
votes
1 answer

If I want to execute an executable from a stored procedure, is there any way to do it other than using xp_cmdshell?

I have an executable on the server. I want to execute that .exe file in my stored procedure. What is the correct way to do it other than using xp_cmdshell?
Himanshu Jindal
  • 43
  • 1
  • 1
  • 7
0
votes
1 answer

How to answer to xp_cmdshell?

I am using SSM and I want to export data with xp_cmdshell. It looks like this: DECLARE @sql NVARCHAR(4000) SELECT @sql = 'bcp "select id, data from tabla" queryout C:\temp\data.dat -S 10.11.11.111 -U XXX -P XXX ' PRINT @sql EXEC xp_cmdshell…
0
votes
0 answers

File not found from within SQL

What I am trying to do is the following: Everyday I get a CSV file that eventually needs to be imported into SQL via Bulk Insert. This all has worked great for a long time but recently, one of the columns in the CSV file contains text that needs to…
Richard_2413
  • 59
  • 2
  • 8
0
votes
1 answer

SQL Server xp_cmdshell query: add variables to command

I have the query working correctly, but I want to be able to add a date value variable within the command. Here is what I have so far: DECLARE @varDate DATE SET @varDate = CAST(DATEADD(day, -1, GETDATE()) AS DATE) EXEC master..xp_cmdshell 'SQLCMD…
C. Ayers
  • 53
  • 1
  • 9
0
votes
1 answer

Executing exe file in xp_cmdshell doesn't work

I have created a user in SQL Server with: CREATE LOGIN adminuser WITH PASSWORD = 'ABCDegf123'; GO EXEC master..sp_addsrvrolemember @loginame = N'adminuser', @rolename = N'sysadmin' GO Then I connected with this user. What I want to do, is trigger…
dzjs
  • 1
  • 3
0
votes
0 answers

SQL's EXEC xp_cmdshell for net share

Another day, another hurdle. Yesterday's victory was short lived. I find that EXEC xp_cmdshell 'net share ProgramdataXYZ=%ALLUSERSPROFILE%\XYZ /grant:everyone,FULL' Works on one machine but not the other. After googling and checking out this and…
Harry A
  • 105
  • 1
  • 10
0
votes
1 answer

while using "EXEC xp_cmdshell net use" in sql procedure how to handle exception

BEGIN TRY EXEC xp_cmdshell "net use Z: \\10.44.111.124\dpsshare Demo@123 /user:balamuralirc /persistent:yes" END TRY BEGIN CATCH SELECT ERROR_NUMBER() AS ErrorNumber ,ERROR_SEVERITY() AS ErrorSeverity ,ERROR_STATE() AS…
Manu C Rajan
  • 153
  • 1
  • 2
  • 13
0
votes
1 answer

xp_cmdshell copy command seldom fails

I am running SQL Server 2005 on Windows Server 2003 machine. I have a requirement to accumulate small text files into a bigger one. So I use exec xp_cmdshell @sql where @sql= 'copy /b'+@sourcePath+@sourceFile+' '+@destinationPath+@NewFileName Both…
0
votes
1 answer

SQL SERVER - reading excel files content and transfer to sql database using xp_cmdshell

I was shocked when I learned that importing the excel data to sql database using OPENROWSET has downsides as it truncates the cells' values of it to 255-length-characters before it passes to the database. I'm now thinking of using xp_cmdshell to…
aj go
  • 637
  • 2
  • 10
  • 27
0
votes
2 answers

Access denied when deleting folders created in SQL Server

I am creating directories with xp_cmdshell but I can't delete them after because of the permission, I am not even allowed to see the owner of the folders. I have to enter in safe mode to be able of delete the folders. I am using SQL Server 2008.
jos3m
  • 117
  • 1
  • 11
0
votes
0 answers

EXECUTE xp_cmdshell from SQL does not execute all commands in batch file

I use EXECUTE xp_cmdshell in a SQL Stored Procedure to call a batch file. All commands in the batch file get executed except for one. The Reporting Services command rs.exe does not execute. There is a proxy account for xp_cmdshell and the…
0
votes
0 answers

BCP - Data duplication during export command

I have a procedure which is for exporting data from table to .DAT file. There's a job running on it which calls SP every 10 Min. .DAT file contains H= column names, B= table data, T= No of rows processed(.SIG file appends this to .DAT file).…
Priyanka
  • 23
  • 1
  • 6