Executing an SP in a new SPID?

  • 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!

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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!

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply