Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Changing Stored Procedure Execution Context

Posted on 2007-11-19
9
231 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
ID: 20316577
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
ID: 20316772
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
ID: 20316830
How do you start a job in the first procedure?

Thanks
Bob
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 35

Expert Comment

by:David Todd
ID: 20316923
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
 

Author Comment

by:rcl58
ID: 20319426
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
ID: 20322328
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
ID: 20324210
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
ID: 20326863
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
ID: 20326889
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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