1

Is there a way to run SQL Server 2019 stored procedures with parameters asynchronously? Calls to this SP will be made several times a day, i.e. this is not one time requirement.

Service Broker can be one option, but this is 15+ years old technology and Microsoft did not try to enhance its functionality.

Agent job can be an option, but I want to submit a job on demand "as and when required". Plus, the stored proc has parameters as well.

I came from Oracle background and there are multiple ways to submit a background job to the Database engine and it will run the job in Async manner.

LowlyDBA - John M
11.1k11 gold badges46 silver badges63 bronze badges
asked Sep 13, 2020 at 23:23
3
  • 2
    Have you considered just using a queue table? Also don’t discount service broker because it hasn’t been enhanced. It just works. Log shipping is older and it still works perfectly fine. Agent hasn’t really improved in all that time either. Just because it isn’t shiny doesn’t make it crap. Commented Sep 14, 2020 at 2:45
  • Thanks @AaronBertrand. I'm relatively new for Sql Server. So far I'm aware of Service Broker and Agent job only. I 'm religiously following BrentOzar and he thinks doing anything in Service Broken is mistake. As far Agent jobs is concerned I will need to find way to pass parameter and run on demand. Queue Table and/or Log Shipping are new info for me, If possible please point me to example or intro for these. In my case when a row is inserted in TabA then job will be submitted and that job will take PkID of TabA as param and do expensive Ins/Upd that not immediately needed. Thanks again Commented Sep 14, 2020 at 5:14
  • 3
    Create a queue table with details / arguments for process. Application inserts details into queue table. Then launches Agent job through TSQL (this is async) (or Agent job runs every X minutes). Agent job reads queue table details and does X. Service broker is the better approach for this kind of thing if you want it all in-engine. From personal experience it can work great, I would just limit yourself to a few hundred messages per minute at most. Commented Sep 14, 2020 at 13:11

1 Answer 1

3

The simplest way is to call sp_start_job and kick off an unscheduled SQL Agent Job. Parameter values can be stored in a table that the job reads from before calling the procedure.

answered Sep 14, 2020 at 16:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.