views:

1656

answers:

1

Hi Im trying to use some T-SQL to move some files from one directory to another. Im using xp_cmdshell to call the move command Just like this:

create table #output(line varchar(2000) null)
insert into #output exec master..xp_cmdshell 'move /y "D:\files\*.txt" "D:\oldfiles"'

But the files inst move and the #output table contains this output from the move command

Access is denied.
Access is denied.
Access is denied.
Access is denied.
Access is denied.
Access is denied.
        0 file(s) moved.
NULL

The sql server proxy account is mapped to the local administrator If i open a command prompt at enter the move command

move /y "D:\files\*.txt" "D:\oldfiles"

The files are moved perfectly

Its all happening on a sql2005 running on a w2k3 server.

Im logged into the server as local administrator

+3  A: 

Can you run a

exec master..xp_cmdshell 'set username'

and tell what this returns?

EDIT: By the OP's comment, the commands are run as NETWORK SERVICE. Allowing NETWORK SERVICE on the directory in question solved the problem.

Tomalak
Then one way to solve it (without the need to reconfigure the SQL Server service account) would be to simply allow NETWORK SERVICE on the directory. – Tomalak
CruelIO
It works! Thank you very much
CruelIO