Execute a stored procedure from a windows form asynchronously and then disconnect?

前端 未结 8 1312
青春惊慌失措
青春惊慌失措 2020-12-08 10:48

I am calling a stored procedure from my application that can take 30 minutes to execute.

I don\'t want to make my user leave the application open for that entire tim

8条回答
  •  轮回少年
    2020-12-08 11:45

    If you really want to close down your application completely, I suggest you define a job in SQL Server Agent, and just execute a T-SQL statement to start that job manually. The syntax is:

    sp_start_job 
         {   [@job_name =] 'job_name'
           | [@job_id =] job_id }
         [ , [@error_flag =] error_flag]
         [ , [@server_name =] 'server_name']
         [ , [@step_name =] 'step_name']
         [ , [@output_flag =] output_flag]
    

    The job would execute your stored procedure. You will have to be a little creative to pass in any arguments. For example, insert the parameters into a "queue" table and have the job process all the rows in the queue.

    Instead of a job, an insert trigger on your queue should work as well.

提交回复
热议问题