且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

超时已过期异常

更新时间:2023-02-26 16:03:14

由于您没有显示很多代码,很难给出任何具体的解决方案。

您的代码尝试将您的代码分成两部分不同的部分,选择和更新。

至少它会更容易找出抛出异常的连接。

还考虑不要使用SELECT *作为它将为您提供您可能需要的更多数据。在这种情况下,您可能只需要表的主键,但很难用很少的信息说。

As you don't show much of your code, is is difficult to give any specific solution.
You code try to divide your code into two different parts, Select and Update.
At least it will be easier to find out which connection it is that throws the exception.
Also consider not to use SELECT * as it will give give you more data that you might need. In this case you might only need the primary key of the table, but it is difficult to say with so very little information.
#region Select
DataTable dtResult = new DataTable();
using (SqlConnection SelectConnection = new SqlConnection(connectionString))
{
    SqlDataAdapter da = new SqlDataAdapter("Select * From A", SelectConnection);
    da.Fill(dtResult);
    da.Dispose();
}
#endregion

#region Update
using (SqlConnection UpdateConnection = new SqlConnection(connectionString))
{

    SqlCommand updateCommand = new SqlCommand();
    updateCommand.Connection = UpdateConnection;


    foreach (DataRow dr in dtResult.Rows)
    {
        // Whatever code you have here
    }
}
#endregion