gpt4 book ai didi

c# - 更改 SqlConnection 超时

转载 作者:IT王子 更新时间:2023-10-29 03:41:58 24 4
gpt4 key购买 nike

我正在尝试覆盖默认的 SqlConnection 15 秒超时,但我收到一条错误消息,指出

property or indexer cannot be assigned because it is read only.

有解决办法吗?

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.

关于c# - 更改 SqlConnection 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10108565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com