Is there ANY way to copy files from within T-SQL other than using xp_cmdshell in the master table?
I am trying to launch a batch file using xp_cmdshell, for example:
declare @command varchar(200)set @command = 'call c:\temp\test.bat'exec master..xp_cmdshell @command
and it doesn't work... I get an error:
xpsql.cpp: Error 997 from GetProxyAccount on line 472
I simply need to copy some files from one location to another but it needs to be from within a T-SQL script and cannot be a Copy Files task in a DTS package =(
Carl, sometimes there's just no application to be had... SQL is it.
Mark, the reason you are getting the error is that you must either have SA permissions or your DBA is going to have to setup a special proxy account for you. The hard part will be both convincing the DBA that you gotta have it to do your job and then them figuring out how to do it.
Now, you could cheat a little bit... when you meet an immovable object, go around it... run your SQL through a batch file that uses OSQL... it'll take a lot more finagling with outputing results sets to files and the like, not to mention some pretty good ol' fashioned DOS knowledge, but it can be done.
I just went through the very same thing with my DBA's... the big concern with xp_CmdShell is that it's very powerful and you can do a lot of damage to the server either maliciously or by accident. It also makes for one hell of a security hole unless you have DBA's that know how to handle the tool. Fortunately, I have good DBA's that said, "you develop it on your desktop server and how to move it to production. We'll figure out how to run it for you." What a bunch of great folks... they setup a special proxy where I can call a special SQL job to run my code by proxy. Because of other security measures they took, if I change the store proc, I can't apply grants to the proc so that even I can't run it if it's been changed. The DBA's have to approve all changes and they're the only ones that can apply the correct grants. And, no one but the special account I log into can run the proc. It's amazing how they've given me the flexibility to run it anytime I need to and have locked it down so well. Like I said, great DBA's.
And to heck with rocks, use a hammer 'cause to a hammer, everything is a nail