3 个解决方案
#1
参考:
public DataTable GetDataTable(SqlCommand sqlCommand)
{
ChangeNullToDBNullValue(sqlCommand);
bool useDefaultConnection = false;
if (sqlCommand.Connection == null)
{
useDefaultConnection = true;
sqlCommand.Connection = new SqlConnection(this.connectionString);
}
else
{
useDefaultConnection = false;
if (sqlCommand.Connection.State != ConnectionState.Closed)
{
throw new ArgumentException("SqlCommand's connection state must be closed.");
}
}
sqlCommand.Connection.Open();
sqlCommand.CommandTimeout = 200;
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
DataTable dt = new DataTable();
da.SelectCommand = sqlCommand;
try
{
da.Fill(dt);
}
catch (Exception ex)
{
DBOperatorLogsWritter.WriteDBErrorLog(ex, sqlCommand);
}
sqlCommand.Connection.Close();
if (useDefaultConnection)
{
sqlCommand.Connection = null;
}
return dt;
}
#2
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx
#3
你这个不是连接的 Timeout ,而是执行的 Timeout了。
#1
参考:
public DataTable GetDataTable(SqlCommand sqlCommand)
{
ChangeNullToDBNullValue(sqlCommand);
bool useDefaultConnection = false;
if (sqlCommand.Connection == null)
{
useDefaultConnection = true;
sqlCommand.Connection = new SqlConnection(this.connectionString);
}
else
{
useDefaultConnection = false;
if (sqlCommand.Connection.State != ConnectionState.Closed)
{
throw new ArgumentException("SqlCommand's connection state must be closed.");
}
}
sqlCommand.Connection.Open();
sqlCommand.CommandTimeout = 200;
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
DataTable dt = new DataTable();
da.SelectCommand = sqlCommand;
try
{
da.Fill(dt);
}
catch (Exception ex)
{
DBOperatorLogsWritter.WriteDBErrorLog(ex, sqlCommand);
}
sqlCommand.Connection.Close();
if (useDefaultConnection)
{
sqlCommand.Connection = null;
}
return dt;
}
#2
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx
#3
你这个不是连接的 Timeout ,而是执行的 Timeout了。