Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2010-04-28 : 07:09:27
|
| I want to move a file using xp_cmdshell declare @tsql varchar(100) declare @FullFileTxt varchar(100) declare @ReadyforImport varchar(100) SELECT @FullFileTxt = 'D:\smartstream\a.txt' SELECT @ReadyforImport = 'D:\smartstream\readyforimport' select @TSQL = 'move ' + @FullFileTxt + '" " ' + @ReadyForImport print @tsql exec master.dbo.xp_cmdshell @TSQL after running it saying the system can not find a file ,though file is there in the specified location .could someone please help on this |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-28 : 07:19:10
|
| Note that the file should exist in the Server's directory and not the system you are working withMadhivananFailing to plan is Planning to fail |
 |
|
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2010-04-28 : 07:41:15
|
ok you are saying it should be in server's directory then how would i move the file using xp_cmdshell on my local machine because my file on my local machine and i have to move it using xp_cmdshellquote: Originally posted by madhivanan Note that the file should exist in the Server's directory and not the system you are working withMadhivananFailing to plan is Planning to fail
|
 |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-04-28 : 08:13:21
|
| When you execute a commend using xp_cmdshell, it's as if you've typed the command into a cmd prompt on the server itself. If the server can't see the file, then neither can xp_cmdshell. In order for the server to see the file, you need to put it into a shared folder on your machine, and grant the user context that SQL Server runs under read access to that folder. Then the server can access it via: \\machineName\sharedFolder\Filename.ext.------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee. |
 |
|
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2010-04-28 : 08:42:27
|
Hi guys Thanks for your input ....But my problem got resolved.It was my silly mistake i was looking for a.txt but at the mentioned location the file was available named a.txt.txt . It was my mistake I just changed the extension and it work fine ..By the way thanks for your input for it quote: Originally posted by DBA in the making When you execute a commend using xp_cmdshell, it's as if you've typed the command into a cmd prompt on the server itself. If the server can't see the file, then neither can xp_cmdshell. In order for the server to see the file, you need to put it into a shared folder on your machine, and grant the user context that SQL Server runs under read access to that folder. Then the server can access it via: \\machineName\sharedFolder\Filename.ext.------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee.
|
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-28 : 08:45:02
|
So sql server and txt-file are on the same machine? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|