I have a server that executing SQL queries against Azure SQL Server using ADO.NET
When I'm trying to run a specific query by my server (using ADO.NET) I get a timeout error, but when I'm executing the same query by SQL Server, I get results after 1-2 seconds.
I tried to increase to timeout in the connection string and in the SqlCommand object with no results.
I saw one potential solution to change the timeout in the SqlCommand object to 0, I tried and got results after a long time, but it works only on my local machine and not on my production server
This is the code I'm using in my server to integrate my DB:
using (var connection = new SqlConnection(ConnectionString))
{
var command = new SqlCommand
{
CommandText = query
};
foreach ( var parameter in parameters)
command.Parameters.AddWithValue(parameter.Key, parameter.Value ?? Convert.DBNull);
command.Connection = connection;
try
{
_logger.Info("Open connection to db");
connection.Open();
_logger.Info("Execute command");
SqlDataReader reader = command.ExecuteReader();
List<Column> columns = CreateColumnList(reader);
}
catch (Exception e)
{
_logger.Error(e);
}
}
This is the exception message I get:
The timeout to perform has expired. The timeout period passed before completing the action or the server is not responding
setoptions.