SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


xp_cmdshell execute scripts that are on c:


xp_cmdshell execute scripts that are on c:

Author
Message
river1
river1
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4576 Visits: 1366
Hi,

I need to use xp_cmdshell to execute a stored procedure that is my c:
The name of the stored procedure is Script22.sql

I have seen the following example on the internet:

exec master.dbo.xp_cmdshell 'osql -E -Sserver1 -i c:\tempightly.sql'


But i think that in SQL Server 2005 the OSQL was replace by CMDSQL, am i correct?
How can i alter this command so that it runs the script in cmdSQL and if the script raises any error, i can catch it?

Thank you
Ron Clarke
Ron Clarke
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1191 Visits: 830
Not sure about catching errors, but as far as running it under SQL 2005 (and 2008), you can substitute "sqlcmd" for "osql". Of course "osql" still works for now (it is deprecated), it is "isql" that was removed.


Have Fun!
Ronzo

Schadenfreude-Mei
Schadenfreude-Mei
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3765 Visits: 1336
Havent tried it but would assume that you would pipe to an output file. something like:

sqlcmd -S . -d master -Q "select name from sys.databases" -o "c:\output.csv"

But obviously inside a XP_cmd... statement.

Hope this helps. :-)

Adam Zacks

-------------------------------------------

Be Nice, Or Leave
Schadenfreude-Mei
Schadenfreude-Mei
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3765 Visits: 1336
Schadenfreude-Mei (7/29/2010)
Havent tried it but would assume that you would pipe to an output file. something like:

sqlcmd -S . -d master -Q "select name from sys.databases" -o "c:\output.csv"

But obviously inside a XP_cmd... statement.

Hope this helps. :-)


SO in your case:

EXEC xp_cmdshell 'sqlcmd -S . -d master -i "c:\sqlscript.sql" -o "c:\output.csv"'

Or something like that. Simples (squeeky meercat noise!)

Adam Zacks

-------------------------------------------

Be Nice, Or Leave
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search