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

Why xp_cmdshell exports empty PDF files from database that stored in image datatype

I have query that extracts PDF files into directory. But for some reason all files are empty (0 KB). Column PDF stored as image datatype. I know its obsolete but I am not the owner of the database. Would you suggest any workaround? CREATE TABLE…
Serdia
  • 4,242
  • 22
  • 86
  • 159
0
votes
3 answers

How i can get file size by SQL

I have file exemple.txt on network space, e.g. q:\folder\exemple.txt I have MS SQL. How i can get file size by sql request ? Desirable use select. Permission - On.
J. Doe
  • 21
  • 1
  • 1
0
votes
1 answer

xp_cmdshell bat file doesn't actually run

I can run this SQL command just fine from SSMS, and the .bat file runs: EXECUTE xp_cmdshell 'C:\ReportPrinting\KarlTest\test.bat @TrxOid' I put it into a stored procedure and, after getting past a lot of permission issues, the stored procedure…
Karl
  • 13
  • 5
0
votes
0 answers

XP_CMDSHELL returns "The syntax of this command is:"

I am trying to make another drive available through SQL. exec xp_cmdshell 'net use G: \\IMAFS01\Finance' works fine but exec xp_cmdshell 'net use J: \\IMA-SQL01\Microsoft SQL Server 2016 /user:[XXX\xxx] /persistent:yes' returns the message…
anonymous
  • 113
  • 13
0
votes
1 answer

call xp_cmdshell with xml parameter

It was created console application that has two param: one is a command like "send" and second is a xml string like "My message". Console application will return something like: "Handled…
apros
  • 2,848
  • 3
  • 27
  • 31
0
votes
2 answers

export data into excel using BCP AND commandShell

I am selecting the data from view I am Getting the error usage: bcp [[db_name.]owner.]table_name[:slice_num] [partition pname] {in | out} [filename] [-m maxerrors] [-f formatfile] [-e errfile] [-d discardfileprefix] [-F firstrow] [-L lastrow] [-b…
0
votes
1 answer

Unable to connect to remote shared path through xp_cmdshell

I am trying to copy a file from a remote path to my local machine using xp_cmdshell in SQL management studio. The following are the steps i use: 1. Establish a connection exec xp_cmdshell 'net use L: \\remoteServer\folder /user:domain\username…
Linda
  • 147
  • 2
  • 20
0
votes
0 answers

Using xp_cmdshell to execute .bat succeed, but does nothing

I'm using MS SQL server 2014 web edition. I created a maintenance plan, and I used a T-SQL statement task to execute xp_cmdshell to execute a batch file. T-SQL statement: exec master.dbo.xp_cmdshell 'Path\XX.bat' When doing so, I get success. But…
0
votes
0 answers

msg through sql server xp_cmdshell

Problem to execute following command shell for msg command through Sql Server 2008 r2 EXEC master..xp_cmdshell 'msg Curious.k /server:CuriousK-PC "Hello"' And Output is : user.name does not exist or is disconnected NULL But from command prompt its…
curious K
  • 145
  • 5
  • 15
0
votes
0 answers

SQL Server - can enabling and disabling xp_cmdshell in multiple queries be harmfull?

I am currently working at one of my clients SQL-Server environment. A year ago I was asked to implement a .csv report generation in a Maintenance Plan I was working on. To do so, I have enabled xp_cmdshell option on the server and used bcp utility.…
0
votes
0 answers

Xp_cmdshell and permissions

I have an SQL non-sysadmin user. I am running xp_cmdshell in stored procedures so I was having issues as expected. I configured a proxy account to allow to run this. I've used the following blog's instructions to do this Blog I've successfully…
Muhammad Usman
  • 10,039
  • 22
  • 39
0
votes
2 answers

Using bcp through a trigger in sql server 2008

The purpose of the trigger is exporting an specific data from a table with bcp after inserting data on that table, so I thought doing it in this way, I know that the trigger waits for bcp, that is waiting for a lock on the table to be released, but…
0
votes
2 answers

I am getting file not found on xp_cmdshell dir on local directory

Here is what I am trying to execute: exec xp_cmdshell 'dir "D:\Data\GS Products" /AD /S /B' This works with every other folder on data that I have tried but not with the one I am trying to use. I am logged in with the admin god privs, I have done…
Phil
  • 11
  • 1
  • 4
0
votes
2 answers

SQL Server Unable to open BCP host data-file

We recently moved all databases from MyServerA to MyServerB. Everything worked fine on MyServerA, but when I try to call the bcp command using xp_cmdshell, I get the following error: Error = [Microsoft][SQL Server Native Client 11.0]Unable to open…
ptownbro
  • 1,240
  • 3
  • 26
  • 44
0
votes
0 answers

SQLState = 37000, NativeError = 137: Must declare the scalar variable "@result"

When I run the following code to output an Sql query to a file, it works fine: exec xp_cmdshell 'bcp "SELECT top 5 * from NK.[dbo].[eclubCustomerDelta]" queryout c:\nk\contacts.txt -c -T' But I have saved my query in another variable earlier in the…
disasterkid
  • 6,948
  • 25
  • 94
  • 179