【问题标题】:How can I set the time out, in the command and the connection?如何在命令和连接中设置超时?
【发布时间】:2019-09-20 20:22:43
【问题描述】:

这是我在 dataset.cs 中的代码。 我必须添加什么来设置连接和命令中的超时?

namespace M_Report
{


    partial class A_DBDataSet
    {

        partial class VP_DataTable
        {
        }
    }
}


namespace M_Report.A_DBDataSetTableAdapters
{
    partial class VD_TableAdapter
    {
    }

    public partial class VP_rofitsTableAdapter {
    }
}

【问题讨论】:

  • 我真的不知道你在问什么
  • 我猜测您接受了您对 ado.net SqlCommand 对象的答复。请尝试更清楚您的问题
  • 谢谢!我在 dataset.cs 中找到了一些要添加的代码。

标签: c# ado.net settimeout sqlcommand connection-timeout


【解决方案1】:

在DataSet.cs中添加这段代码:

namespace P.A_DBDataSetTableAdapters
{
    public partial class VD_TableAdapter
    {
        public int CommandTimeout
        {
            set
            {
                int i = 0;
                while ((i < this.CommandCollection.Length))
                {
                    if ((this.CommandCollection[i] != null))
                        this.CommandCollection[i].CommandTimeout = value;
                    i = (i + 1);
                }
            }
        }
    }
}

Form.cs 中的这段代码: this.vD_TableAdapter.CommandTimeout = 1800;

【讨论】:

  • 效果很好。谢谢。
【解决方案2】:

如果您想为特定查询设置超时,那么 CommandTimeout 就是最佳选择。

command.CommandTimeout = 60; //default is 30 seconds.

或者你也可以在连接字符串中添加它

connect timeout=180;

【讨论】:

    猜你喜欢
    • 2012-05-17
    • 2014-08-13
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 2016-12-27
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多