Solved

Return Status from SQL Server - Executing Stored Procedure

Posted on 2001-06-27
3
661 Views
Last Modified: 2008-02-01
I'm using VB6 against SQL Server and I need some help.
From a drop-down menu in my VB app, I'd like to execute a stored procedure (an update which passes some parameters)
on SQL Server.

I'd like the sp to execute in the background and then pass a return code on completion or failure of the sp to the VB program;
Possibly display a message box to the user or some popup to let them know that the job completed.

Can anyone suggest the best way to do this?
I know sql server comes with a bunch of built-in sps; but the one closest to what I need is only suitable for OLE Automation.

Thanks in advance.

John
0
Comment
Question by:jtrapat1
3 Comments
 

Expert Comment

by:MarioK
ID: 6232153
Don't know if this will help, but here go's

After the SQL statement executed in your store procedure
you can query the value of the @@Error SQLserver variable
while still in the SP. If the @@Error = 0 then the SQL
statement executed without errors. You can then set a
return variable that VB will be able to to intrepid.

MK



0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6232454
Is this "job" lengthy (say minutes/hours)? in that case i would define a sql job (look under the SQL Server Agent part of the server in the Enterprise manager), you find a Jobs folder.

To start such a job, you can use the sp_startjob stored procedure. to find the result of this is a little bit more complicated...

If this goes into the direction you want, we can continue to solve the small technical details...

Cheers
0
 
LVL 7

Accepted Solution

by:
John844 earned 200 total points
ID: 6232648
one way to chest is to send some identifyer to the stored procedure to let you know what user is running stored procedure currently.  inside the stored procedure execute your items, trap any errors using @@Error.  If an error occurs, write a item to a log table with the userid time and error message.  if no errors have occured at the bottom of the sp, then write a row to the log table indicating success.  Execute the sp asyncronously without expecting a recordset back(adexecutenorecords).  check the contents of the table periodically to inform user of success or failure.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now