Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


getting error "The system cannot find the path specified." using xp_cmdshell


getting error "The system cannot find the path specified." using xp_cmdshell

Author
Message
asif_ku
asif_ku
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 3
Hi,

I am getting error "The system cannot find the path specified." using xp_cmdshell, tyring to copy file from one folder to another. Following is code i execute:

DECLARE @fn char(6),
@cmd varchar(100)

SET @fn=REPLACE(convert(char(8),getdate(),1),'/','')
SET @cmd ='Move C:\Shippment_Tracking\ShippmentTracking.txt C:\Shippment_Tracking\Archive\'+@fn+'.txt'
EXEC master..xp_cmdshell @cmd
Andras Belokosztolszki
Andras Belokosztolszki
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1387 Visits: 1585
A simple question: does this folder actually exist on the server on which SQL Server is running? The xp_cmdshell is executed in the security context of the SQL Server service. Does this have permissions to the folder? So does a simple dir work:

EXEC master..xp_cmdshell 'dir C:\Shippment_Tracking\'



Regards,
Andras



Andras Belokosztolszki, MCPD, PhD
GoldenGate Software
asif_ku
asif_ku
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 3
First of all thanks for quick respond!

Yes, that folder exisit on same machine where Sql server is running.
I am not sure how to give permission to that folder? Can u plz let me know the steps to do so?

Thanks.
Adam Bean
Adam Bean
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1215 Visits: 2160
asif_ku (1/23/2008)
First of all thanks for quick respond!

Yes, that folder exisit on same machine where Sql server is running.
I am not sure how to give permission to that folder? Can u plz let me know the steps to do so?

Thanks.


xp_cmdshell will use the account which is running your SQL server.

To figure out the account running SQL:
- Start | Run | services.msc
SQL2000
- MSSQLSERVER(INSTANCENAME)
SQL2005
- SQL Server(INSTANCENAME)
- Double click the service
- Click Log On
- Note the account running the service

Now that you know the account, check your folder permissions
- Right click the folder in question
- Go to Properties / Security
- Ensure the account in question has the appropriate permissions (read/write from the sounds of it)

---
SQLSlayer
Making SQL do what we want it to do.
get-12
get-12
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1
analogue xp_cmdshell
-----------------------
MSSQL2000 :
nothing

MSSQL2005 :
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
-----------------------
declare @iShl int, @iStm int, @iStdOut int, @hr int, @EndOfStream int,
@strText nvarchar(4000), @cmd nvarchar(4000)
set @cmd = 'Exec("cmd /c ping -n 3 -w 1000 www.ru")'

EXEC @hr = sp_OACreate 'Wscript.Shell', @iShl OUT
EXEC @hr = sp_OAMethod @iShl, @cmd, @iStm out
EXEC @hr = sp_OAGetProperty @iStm, 'StdOut', @iStdOut out
EXEC @hr = sp_OAGetProperty @iStdOut, 'AtEndOfStream', @EndOfStream out
WHILE @EndOfStream = 0 BEGIN
EXEC @hr = sp_OAGetProperty @iStdOut, 'ReadLine', @strText out
print @strText
EXEC @hr = sp_OAGetProperty @iStdOut, 'AtEndOfStream', @EndOfStream out
END
EXEC @hr = sp_OADestroy @iShl
-----------------------
Hehe
Lester Policarpio
Lester Policarpio
SSC-Addicted
SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)SSC-Addicted (407 reputation)

Group: General Forum Members
Points: 407 Visits: 2459
Andras Belokosztolszki (1/22/2008)
A simple question: does this folder actually exist on the server on which SQL Server is running? The xp_cmdshell is executed in the security context of the SQL Server service. Does this have permissions to the folder? So does a simple dir work:

EXEC master..xp_cmdshell 'dir C:\Shippment_Tracking\'



Regards,
Andras


Also check for this :

EXEC master..xp_cmdshell 'dir C:\Shippment_Tracking\Archive\'



I had almost the same situation as you are ( for me i used copy instead of move) i solved my problem by letting the value of the variable in a single line...

I also tested your query i just replaced the path and it works for me..

"-=Still Learning=-"

Lester Policarpio
Ian Yates
Ian Yates
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1056 Visits: 445
Also, just to future proof your code, enclose the filenames and paths in double quotes as in

"c:\my folder\my file.txt" because without them you have 4 parameters to move rather than the expected 2.



rajeshpandyan32
rajeshpandyan32
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 19
i too had the same issue in Production servers even with proper folder acess rights.
adding double quotes to path worked fine
Rynga
Rynga
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 159
Adding double quotes saved my hoursSmile
mpepe 21547
mpepe 21547
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 51
I am having a similar issue:

EXEC master..xp_cmdshell
"dir \\fserver1\NextgenRoot\Prod\EMR\Images\ImageSaved\84C06D96-D350-47ED-B26D-BF1A794D93A6.pdf"

Results:

Volume in drive \\fserver1\NextgenRoot is Data
Volume Serial Number is 3CEC-F907
NULL
Directory of \\fserver1\NextgenRoot\Prod\EMR\Images\ImageSaved
NULL
09/28/2014 01:29 PM 413,455 84C06D96-D350-47ED-B26D-BF1A794D93A6.pdf
1 File(s) 413,455 bytes
0 Dir(s) 15,483,371,520 bytes free
NULL

But when I try to move that file:

EXEC master..xp_cmdshell
'MOVE "\\fserver1\NextgenRoot\Prod\EMR\Images\ImageSaved\C06D96-D350-47ED-B26D-BF1A794D93A6.pdf" "\\fserver1\NextgenRoot\IHS_DocsImagesToBeRemoved\C06D96-D350-47ED-B26D-BF1A794D93A6.pdf"'

Results are:
The system cannot find the file specified.

Clearly the file is there but the move command cannot find it. What am I missing?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search