2

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))
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
fieldingmellish
  • 1,473
  • 3
  • 16
  • 21

3 Answers3

5

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

Jason
  • 1,119
  • 8
  • 9
  • +1 - beat me by 22 seconds (but no link, so who really won?:-) ) – Harper Shelby Oct 29 '09 at 15:13
  • If you use this method, make sure you don't put your SqlConnection in a using clause or the connection will be disposed before the command is done executing. – Aheho May 12 '14 at 18:42
4

Use the asynchronous method call BeginExecuteNonQuery. From the MSDN page

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

Harper Shelby
  • 16,475
  • 2
  • 44
  • 51
0

You could run that code from a background thread. You could look into the BackgroundWorker object.

Ryan Alford
  • 7,514
  • 6
  • 42
  • 56