我有一个并行运行12个线程的框架-每个线程将有不同的测试,但可能必须从sql连接得到结果
这样做-我收到下面的错误-有没有一种方法,我可以在我的代码中做任何变通,使它不失去并行线程的工作
system.data.sqlclient.sqlexception:执行超时已过期。操作完成前已过超时时间,或者服务器没有响应。。
我的配置:
代码:
private static void ExecuteQuery(TestConfigurationCDO testConfiguration, string query)
{
using (var sqlConnection = new SqlConnection(testConfiguration.ConnectionString))
{
var orderTable = sqlConnection.ExecuteQuery(query);
}
}
//Execution
public static DataTable ExecuteQuery(this SqlConnection sqlConnection, string queryString)
{
if (sqlConnection == null) throw new ArgumentNullException(nameof(sqlConnection));
DataSet dataset;
try
{
//Checking the state of the connection
if (sqlConnection.State == ConnectionState.Closed ||
sqlConnection.State == ConnectionState.Broken)
sqlConnection.Open();
SqlDataAdapter dataAdaptor = new SqlDataAdapter
{
SelectCommand = new SqlCommand(queryString, sqlConnection) { CommandType = CommandType.Text }
};
dataset = new DataSet();
dataAdaptor.Fill(dataset, "table");
sqlConnection.Close();
return dataset.Tables["table"];
}
catch (Exception e)
{
dataset = null;
sqlConnection.Close();
Console.WriteLine("ERROR {0}", e);
//LogHelpers.Write("ERROR :: " + e.Message);
return null;
}
finally
{
sqlConnection.Close();
dataset = null;
}
}
暂无答案!
目前还没有任何答案,快来回答吧!