xp_cmdshell Return result output

Good Afternoon


Earlier today chapmandew helped me out with getting my S/P to run a .sql script which is being executed from a VB.net application.    After doing some testing here, I realized I forgot to account for something...success/error return.  HI attached the S/P as a code snippet.

I execute this from my VB.net application using the following line of code:
 Exec LBSI_RunScripts 'C:\Enhance\Resources\CrystalScripts\MaintainParam.sql','(local)','3DDemo'

If I send over an invalid path, I don't know how to let the VB.net application know that the script was not produced due to an error? Is there some way to pass back an error/result code?  When I run the above line from Management Studio with the path spelled wrong, I get a message indicating bad filename in Management Studio.  How can I communicate that back to the calling program?

Thanks for the help,

ALTER Procedure [dbo].[LBSI_RunScripts]
            @FilePathName nvarchar(100),
            @DBServerName nvarchar(100),
            @DBName nvarchar(50)
declare @sql nvarchar(max)
declare @error int
SET @sql = 'xp_cmdshell ''sqlcmd -S ' + @DBServerName + ' -d ' + @DBName + ' -i ' +  @FilePathName + ''''
EXEC sp_executesql @sql

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashish PatelCommented:
when something gets executed by xp_cmdshell, then the output from it never gets stored or in other words we cant fetch the output for further use. Its just a message dispaly.
Jimbo99999Author Commented:

I was not aware of that.  Let's see then...how can I find out if the execution ended successfully or not.
Is there any kind of command or way to check if a S/P exists?  Kind of like:  If IsPresent(S/P name).

Ashish PatelCommented:
select * from sysobjects where object_name(id)= 'SPNAME'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimbo99999Author Commented:

Excellent...I am cooking with Crisco now.  

Thanks for the help,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.