By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,364 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,364 IT Pros & Developers. It's quick & easy.

Osql error trapping

P: 2
I am running osql command that goes and grabs files from my folder and runs one script at a time and loops though all the files in that folder. Most of the files and simple inserts or creation of stored procedures.

Problem is that I want to exit out from osql if there is any error encountered while runing the script..

I am using following command


SELECT @cmdstr = 'osql -E -S ' + @servername + ' -d ' + @dbname + ' -n -i ' + @input_full_path -- ' >> ' + @outputfile

--show script processing
PRINT 'Processing script: ' + @scriptname + '..'

-- Cursor - go grab next file from folder

I tried

EXEC @errorstate=master.dbo.xp_cmdshell @cmdstr
print @errorstate
IF @errorstate<>0
CLOSE crs_scripts
DEALLOCATE crs_scripts
RAISERROR('xp_cmdshell returned error while running script: %s', 15,3,@scriptname)

but it only takes care of osql specific errors and not the actual script run time error..

Please help ...
Mar 18 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 2,878
1. What version are you using?

2. Which part of the script you want to trap the error?

-- CK
Mar 19 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.