开发者

SqlCommand object - set it and forget it?

开发者 https://www.devze.com 2022-12-09 23:20 出处:网络
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.

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
                                                    ex开发者_开发技巧ec sp_Get_Bp_Data2          
                                                    exec sp_Get_Bp_Data3
                                                    exec sp_channel_data1
                                                    exec sp_channel_data2
                                                    exec sp_channel_data3
                                                    ", con))


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


Use the asynchronous method call BeginExecuteNonQuery. From the MSDN page

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消