Solved

Changing Stored Procedure Execution Context

Posted on 2007-11-19
9
227 Views
Last Modified: 2013-11-26
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?
0
Comment
Question by:rcl58
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 10

Accepted Solution

by:
MrClyfar earned 400 total points
Comment Utility
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
 
LVL 35

Expert Comment

by:David Todd
Comment Utility
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
 

Author Comment

by:rcl58
Comment Utility
How do you start a job in the first procedure?

Thanks
Bob
0
 
LVL 35

Expert Comment

by:David Todd
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:rcl58
Comment Utility
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
 
LVL 35

Assisted Solution

by:David Todd
David Todd earned 50 total points
Comment Utility
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
 
LVL 25

Expert Comment

by:imitchie
Comment Utility
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
 

Author Comment

by:rcl58
Comment Utility
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
 
LVL 25

Assisted Solution

by:imitchie
imitchie earned 50 total points
Comment Utility
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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

12 Experts available now in Live!

Get 1:1 Help Now