xp_cmdshell Return result output

Good Afternoon

Experts:

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,
jimbo99999


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

Open in new window

Jimbo99999Asked:
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.
0
Jimbo99999Author Commented:
asvforce:

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).

Thanks,
jimbo99999
0
Ashish PatelCommented:
select * from sysobjects where object_name(id)= 'SPNAME'
0

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:
asvforce:

Excellent...I am cooking with Crisco now.  

Thanks for the help,
EJD
0
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.