Click here to Skip to main content
15,904,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This setup of a variable for use as a filename doesn't hold any water if I try to execute it from the script editor as a line item.

SQL
DECLARE @scriptfile varchar(4000)
SET @scriptfile = 'c:\users\fith.sql'
EXECUTE xp_cmdshell @scriptfile


[EXEC sp_configure 'xp_cmdshell', 1 ... has been done]

The interface enters either a long execute wait phase out of which it never returns or it completes successfully there at the message bar but doesn't actually change anything in the database per the code.

Another switch?

WSServer2K8 R2
SSMSE 64 bit
Posted
Updated 21-Dec-11 9:32am
v3

1 solution

The xp_cmdshell executes an OS command so basically if you execute a SQL script using xp_cmdshell, it tries to execute the SQL statements in command prompt.

If you want to run a SQL script, try executing SQLCMD[^] using xp_cmdshell and give the sql script to sqlcmd as a parameter.

So something like:
SQL
SET @scriptfile = 'sqlcmd -i c:\users\fith.sql' -S... -U...
 
Share this answer
 
Comments
RedDk 21-Dec-11 20:26pm    
Yes,

Thanks Mika. I've done this before. The form "EXEC xp_cmdshell sqlcmd -S machine\instance -i c:\users\fith.sql". The thing I was trying to recall was actually WHY I was avoiding that :out (.bat) outside of the shell.

It just seemed like there should have been a shell but not in that batch run sense.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900