Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SqlCommand object - set it and forget it?

Tags:

c#

sqlcommand

I'm using SqlClient.SqlCommand object to run a few stored procs on my db. Normally when I run these manually via Query Analyzer they take up to 15 minutes to complete.

So obviously when I run them using the SqlCommand object I get a SqlCommand timeout.

I know I could set the timeout property to a very high number, but I'm wondering if alternatively there's a way to just kickoff the procs and disconnect. I don't need a return value.

Any suggestions? I'm not interested in optimizing the processing time of each sp here, just trying to determine if there's a 'set it and forget it' option.

Here's the content of the SqlCommand object:

using (SqlCommand cmd = new SqlCommand(@"update tbl_SYS_DATE set RPT_DATE = @inputDate
                                                    exec sp_Get_Bp_Data1
                                                    exec sp_Get_Bp_Data2          
                                                    exec sp_Get_Bp_Data3
                                                    exec sp_channel_data1
                                                    exec sp_channel_data2
                                                    exec sp_channel_data3
                                                    ", con))
like image 649
fieldingmellish Avatar asked May 30 '26 21:05

fieldingmellish


2 Answers

You can use an async method, like BeginExecuteNonQuery. The timeout is ignored for that.

like image 155
Jason Avatar answered Jun 02 '26 09:06

Jason


Use the asynchronous method call BeginExecuteNonQuery. From the MSDN page

The CommandTimeout property will be ignored during asynchronous method calls such as BeginExecuteReader.

like image 44
Harper Shelby Avatar answered Jun 02 '26 10:06

Harper Shelby