Changing Stored Procedure Execution Context

I have a stored procedure that my user accesses from MS VB.Net. At the end of the sproc1 I want to execute a different sproc2 but do the return so my user can continue. In other words, I do not want my user to wait for the completion of sproc2 to continue.
How can I do this?
rcl58Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jason EvansConnect With a Mentor Senior Software DeveloperCommented:
Hi there.

What you could use here ia asynchronous command execution. Here's a good link which explains the concept:

http://www.devx.com/dotnet/Article/26747

Basically the idea is the your code makes an asynchronous call via ADO.NET to the Sql Server, thus whilst in the background this call is being made, the user can carry on their work.

Experiment with the example in the link, it should give you a good grounding.

Hope this helps.
Jas.
0
 
David ToddSenior DBACommented:
Hi,

Another technique is for the first procedure to start a job - create the job even if it has to, and then return. Job is running second procedure.

HTH
  David
0
 
rcl58Author Commented:
How do you start a job in the first procedure?

Thanks
Bob
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
David ToddSenior DBACommented:
Hi Bob,

Use sp_add_job to create the job, use sp_add_jobstep to add a step that calls the procedure, sp_start_job to start the job you have just created.

specifying a @delete_level = ] delete_value with 3 means that when your job completes it will be deleted, ie cleaned up afterwards.
Values are
Value Description
0 Never (default)
1 On success
2 On failure
3 Always

HTH
  David
0
 
rcl58Author Commented:
Thanks David,

That will definitely do the trick. Unfortunately, I also need this to run on SQL Express and it doesn’t have the SQL Server Agent. Any other ideas?

Thanks again,
Bob
0
 
David ToddConnect With a Mentor Senior DBACommented:
Hi,

The other scheduler is the Windows scheduler, but I'm not sure I'd try it in your context.

My impression is that what you are wanting to do is bigger than SQL Express ... that is, you have two options: 1) upgrade Express to Workgroup or Standard, 2) forget about using SQL Agent and use the suggestion about ado.net.

Cheers
  David
0
 
imitchieCommented:
depending on your skill level...

create a script file containing what you want to execute
use the Shell/Process object to execute the script using a Command Line

sqlcmd -S (local) -d nss -U <user> -P <password> -i myscript.sql 2>> script.log

you can read the script.log later

p/s remove -U and -P if using NT authentication
0
 
rcl58Author Commented:
imitchie,
Thanks for your help. Is the Shell/Process object available in SQL or are you talking about shelling from VB? If it is available in SQL how can I find it in the help?

Thanks again,
Bob
0
 
imitchieConnect With a Mentor Commented:
i meant from VB
http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.aspx

Process.Start does not wait, the closest i can describe it is from the command window (cmd.exe)
"start excel.exe"    << doesn't wait
0
All Courses

From novice to tech pro — start learning today.