fieldingmellish
fieldingmellish

Reputation: 1483

SqlCommand object - set it and forget it?

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))

Upvotes: 2

Views: 451

Answers (3)

Harper Shelby
Harper Shelby

Reputation: 16583

Use the asynchronous method call BeginExecuteNonQuery. From the MSDN page

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

Upvotes: 4

Jason
Jason

Reputation: 1149

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

Upvotes: 5

Ryan Alford
Ryan Alford

Reputation: 7594

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

Upvotes: 0

Related Questions