Continue running SQL query after closing the connection

In SQL Server, can I call a long-term stored procedure, close the connection, and end it? I don't care about the result. Essentially, I want to say "Hey SQL, do it on your own server."

I want you to not have to do any service to sit with an open connection and wait for it.

+4
source share
2 answers

You can also use the SQL agent job to start a procedure that does not have a schedule, and then issue the SQL command to run the job using "EXEC msdb.dbo.sp_start_job @job_name = '". If you need to change the command often this may not be ideal, but it can be done using SQL calls if necessary.

+1
source

You want to use BeginExecuteNonQuery(AsyncCallback, Object) , and then use a callback method that actually does nothing. It should be noted that the connection will not actually be closed.

MSDN SqlCommand.BeginExecuteNonQuery Method

Alternatively, you can use Service Broker for the request queue to start the stored procedure. However, there is a small plumbing. Perhaps this is not worth your situation. Especially if you are not using Service Broker for anything else. The advantage here is that the connection can be closed immediately after the queue with Service Broker, and placing messages in the queue is a very fast operation.

+2
source

Source: https://habr.com/ru/post/1381795/


All Articles