Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Executing an SP in a new SPID? Expand / Collapse
Author
Message
Posted Thursday, August 1, 2013 11:43 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, August 11, 2014 5:59 PM
Points: 72, Visits: 400
Hi all,

I'm coding a stored procedure which will be the control mechanism for a series of ETL subprocesses. This control procedure will run through several loops, monitoring various states, and executing these subprocess stored procedures when needed. The challenge is, I'd like to execute each of these subprocess stored procedures in their own session, so that they can run in parallel. I don't want the control procedure to wait for the completion of any of the subprocess stored procs.

I think I could do this with xp_cmdshell calling SQLCMD, but that seems pretty kludgy, and I'd have to convince our admins to enable xp_cmdshell. I think I could also create, execute, and delete a SQL Agent job on the fly, but that seems even more kludgy. Is there a simpler way to execute a stored procedure in a new SPID?

Thanks!
Post #1480056
Posted Thursday, August 1, 2013 11:57 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 5:47 PM
Points: 12,910, Visits: 32,020
it really depends on what you are doing to give you a solid answer.

service broker calls run asynchronously; (sending mail via sp_send_dbmail is one common example) so you'd need to add a service broker that can execute a specific command or set of commands.


you could start with a search for "sql server service broker example", and start from there;
do you really need multiple async processes , or just to have one process do a bunch of stuff async so you can return control to your proc immediately??


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1480063
Posted Thursday, August 1, 2013 12:32 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, August 11, 2014 5:59 PM
Points: 72, Visits: 400
Excellent, thanks, I'll look into it! I'm not really familiar with service broker, but it sounds like a potential solution. To answer your question, I really do need multiple async processes. The control procedure is managing data loads for hundreds of tables; it loops repeatedly, checking all sorts of indicators to determine when each table is ready to load, then it executes the SP which loads that table. I'd like each of those table-load SP's to execute asynchronously.

I'm looking for the simplest solution possible. I was hoping there was some switch for EXECUTE or sp_executesql that would launch an SP in a new SPID, or some other simple tweak I can make to get these SP's to process in parallel. All ideas are welcome!
Post #1480085
Posted Thursday, August 1, 2013 12:51 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 5:47 PM
Points: 12,910, Visits: 32,020
ok, it sounds like a single service broker would work, but that you would call it 100 times, once for each table, for example.

if we can help with the details, let us know.


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1480098
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse