如何在命令和连接中设置超时?

How can I set the time out, in the command and the connection?

这是我在 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 {
    }
}

如果您想要特定查询的超时,那么 CommandTimeout 就是一种方式。

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

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

connect timeout=180;

在 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;