我正在try 覆盖默认的SqlConnection超时(15秒),但收到一个错误,指出

无法分配属性或索引器,因为它是只读的.

有办法吗?

using (SqlConnection connection = new SqlConnection(Database.EstimatorConnection))
{
   connection.Open();

   using (SqlCommand command = connection.CreateCommand())
   {
       command.CommandType = CommandType.StoredProcedure;
       connection.ConnectionTimeout = 180; // This is not working 
       command.CommandText = "sproc_StoreData";
       command.Parameters.AddWithValue("@TaskPlanID", order.Projects[0].TaskPlanID);
       command.Parameters.AddWithValue("@AsOfDate", order.IncurDate);

       command.ExecuteNonQuery();
    }
}

推荐答案

如果您希望为特定查询提供超时,那么CommandTimeout是前进的方向.

它的用途是:

command.CommandTimeout = 60; //The time in seconds to wait for the command to execute. The default is 30 seconds.

.net相关问答推荐

等待时 Blazor 服务器按钮刷新

更改列表中的值

Web API 中基于令牌的身份验证,无需任何用户界面

AutoMapper 的替代品

将客户端证书添加到 .NET Core HttpClient

生产代码中的 System.Diagnostics.Debug.WriteLine

使用 C# 清除文本文件的内容

托管和非托管代码、内存和大小有什么区别?

.Net 中的 Decimal.One、Decimal.Zero、Decimal.MinusOne 的用途是什么

如何等到远程 .NET 调试器附加

如何通过 LINQ 比较没有时间的 DateTime?

如何将 UI Dispatcher 传递给 ViewModel

C# 方法可以定义为采用的最大参数数是多少?

react 式扩展使用的好例子

将记录器作为单身人士是一个好习惯吗?

在 .NET 中获取默认打印机的最佳方法是什么

说明 C# 中 volatile 关键字的用法

铸造:(NewType)与对象作为NewType

根据条件从列表中删除项目

Uri.Host 和 Uri.Authority 有什么区别