CHR*_*LLE 60 c# sql ado.net connection-timeout
我有一点问题,希望有人可以给我一些建议.我正在运行一个SQL命令,但它似乎需要这个命令大约2分钟才能返回数据,因为有很多数据.但是默认连接时间是30秒,如何增加它,并将其应用于此命令?
public static DataTable runtotals(string AssetNumberV, string AssetNumber1V)
{
DataTable dtGetruntotals;
try
{
dtGetruntotals = new DataTable("Getruntotals");
//SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 6);
//AssetNumber.Value = AssetNumberV;
SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 10);
AssetNumber.Value = AssetNumberV;
SqlParameter AssetNumber1 = new SqlParameter("@AssetNumber1", SqlDbType.VarChar, 10);
AssetNumber1.Value = AssetNumber1V;
SqlCommand scGetruntotals = new SqlCommand("EXEC spRunTotals @AssetNumber,@AssetNumber1 ", DataAccess.AssetConnection);
// scGetruntotals.Parameters.Add(AssetNumber);
scGetruntotals.Parameters.Add(AssetNumber);
scGetruntotals.Parameters.Add(AssetNumber1);
SqlDataAdapter sdaGetruntotals = new SqlDataAdapter();
sdaGetruntotals.SelectCommand = scGetruntotals;
sdaGetruntotals.Fill(dtGetruntotals);
return dtGetruntotals;
}
catch (Exception ex)
{
MessageBox.Show("Error Retriving totals Details: Processed with this error:" + ex.Message);
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
Ehs*_*san 109
由于有大量数据,它需要大约2分钟才能返回数据
糟糕的设计.考虑在这里使用分页.
默认连接时间是30秒,我该如何增加它
当您面临命令的暂停时,因此您需要增加sql命令的时间.您可以在命令中指定它
// Setting command timeout to 2 minutes
scGetruntotals.CommandTimeout = 120;
Run Code Online (Sandbox Code Playgroud)
Aja*_*y P 21
添加你的超时SqlCommand.请注意时间是秒.
// Setting command timeout to 1 second
scGetruntotals.CommandTimeout = 1;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
177813 次 |
| 最近记录: |