Alex Lonyay

Alex Lonyay

  • NA
  • 123
  • 8.7k

In MS Test - running parallel tests - sql timeout comes

May 20 2020 5:18 AM
I have framework which runs 12 threads parallel - each will have different test but may have to get result from sql connection
Doing so - I'm receiving below error - Is there a way where I can do any workaround in my code to make it work without loosing parallel threads
System.Data.SqlClient.SqlException: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding..
My Config:
<add name="ConnectionString1" connectionString="data source=54.154.178.120;initial catalog=test;persist security info=true;user id=admin;password=admin" providerName="System.Data.SqlClient" />
Code:
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;
}
}

Answers (2)