Asynchronous call of a SQL Server stored procedure in C# -


Is it possible that call SQL Server stored procedure asynchronous via C # ?

I have a stored procedure that writes a backup of a specific database (this could take a lot of time to complete) and I want to show the progress of the backup process in a windows form (for this I I use it). Or should I use background control and run the SP in some background (own thread)?

In your SqlCommand you can startExecuteNonQuery and < You can run asynchronous commands by using Code> EndExecuteNonQuery . The latter will be blocked until its work will be done. Although it will not report progress from the server how the backup is going on - for this I am using a Marquee progress bar.

EndExecuteNonQuery UI (depending on how you handle it), you will need a background thread. If you use it, you can not use the start XXX andxax methods and synchronize it on the background thread - BackgroundWorker this Is best for

In order to avoid using the background thread in the UI, instead of blocking the end XXX you will need to register the callback and handle the resulting event (calling < Code> endXXX handler in this event, but it will return immediately).

Update: According to a comment, for asynchronous calls in the SQL command / connection stuff, you must specify: The more in the connection string:

< / P>

  server = myServerAddress; Database = myDataBase; Integrated security = true; Asynchronous processing = true;  

or in the code using the connection string creator:

  builder.AsynchronousProcessing = true;  

Comments