May 25, 2005 at 11:44 am
How can I move a text file within a stored Prcoedure?
May 25, 2005 at 11:48 am
R u talking about an actual file or a text column?
May 25, 2005 at 11:51 am
I am talking about an actual text file
May 25, 2005 at 11:54 am
Maybe someone has a better solution... but providing that this is for administrative work :
EXEC master..xp_cmdshell 'dos command to move file here', no_output
May 25, 2005 at 12:11 pm
Stored procedure using xp_cmdshell:
CREATE PROCEDURE DeanTest(@FileName1 varchar(255), @FileName2 varchar(255)) AS
Declare @cmd varchar(2000)
Select @cmd = 'move \\netservice2\public\Dean\Junge\DeanTest.txt \\netservice2\public\Dean\Junge\DeanTest.process'
Print @cmd
SELECT @cmd = 'master..xp_cmdshell ' + '''' + @cmd + ''
Print @cmd
Exec @cmd
GO
Here is the error:
move \\netservice2\public\Dean\Junge\DeanTest.txt \\netservice2\public\Dean\Junge\DeanTest.process
master..xp_cmdshell 'move \\netservice2\public\Dean\Junge\DeanTest.txt \\netservice2\public\Dean\Junge\DeanTest.process
Server: Msg 203, Level 16, State 2, Procedure DeanTest, Line 8
The name 'master..xp_cmdshell 'move \\netservice2\public\Dean\Junge\DeanTest.txt \\netservice2\public\Dean\Junge\DeanTest.process' is not a valid identifier.
Any ideas
May 25, 2005 at 12:25 pm
ok,
CREATE PROCEDURE DeanTest(@FileName1 varchar(255), @FileName2 varchar(255)) AS
Declare @cmd varchar(2000)
Select @cmd = 'move \\netservice2\public\Dean\Junge\DeanTest.txt \\netservice2\public\Dean\Junge\DeanTest.process'
Print @cmd
SELECT @cmd = 'master..xp_cmdshell ' + '''' + @cmd + ''''
Print @cmd
--exec master..xp_cmdshell 'move \\netservice2\public\Dean\Junge\DeanTest.txt \\netservice2\public\Dean\Junge\DeanTest.process'
exec @cmd
GO
The command works, but not when using the exe @cmd, am I not putting @cmd toegether right?
May 25, 2005 at 12:37 pm
The final Solution that works is:
CREATE PROCEDURE MoveFile(@FileName1 varchar(255), @FileName2 varchar(255)) AS
Declare @cmd varchar(2000)
Set @cmd = 'move '+@FileName1+' '+@FileName2
exec master..xp_cmdshell @cmd
GO
May 25, 2005 at 12:38 pm
That's what I was about to finish typing .
June 24, 2005 at 12:12 pm
I can't make it work! I have the following error:
Access is denied.
-----------------------------------------------
use master
declare @FileName1 varchar(100)
declare @FileName2 varchar(100)
declare @cmd varchar(1000)
set @FileName1 = 'C:\Data\Rhapsody\NCWTExtract\*.*'
set @FileName2 = '\\server\Data\Rhapsody\CWTExport\'
Set @cmd = 'move '+@FileName1+' '+@FileName2
exec xp_cmdshell 'bcp accRepository.dbo.CWT_Extract_Formatted out C:\Data\Rhapsody\NCWTExtract\temp.csv -t, -Sosl-win2003 -U -P -c', NO_OUTPUT
exec xp_cmdshell @cmd
Where C:\Data\.. ' is from local server, where the SQL Server resides at (i.e. DB server); whereas \\server\Data\...' is referring to another machine, says web server.
June 24, 2005 at 8:54 pm
make sure that the account the server is using has access to the network, also make sure he can access the said folders and that he can create files in it.
June 25, 2005 at 8:31 am
The use of xp_CmdShell is considered to be a security risk by most DBA's and, I believe, the default is you must have"SA" (not just "dbo" rights to use it. You can have your DBA grant rights to it just for you.
--Jeff Moden
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply