We have an app which is hosted on an on-premise infrastructure. The app takes around 20 calls per sec. There are 40 servers on which the app is installed in a load balanced fashion. Each servers hosts other 8 to 10 app on a shared basis. Out of all apps only one app is having SQL Server connectivity issues. The connectivity issues is intermittent and appears with many different different error messages. The app is taking 20 calls per sec and each call in turn might make around 10 SQL Server connections and runs simple select and insert queries.
We checked SSL settings on client and server and there is no issue. No DB table locks are on the DB Server. We checked DB server, network and everything is fine. No memory or CPU issue on any of the server. No single issue is observed for any other app installed on the same application servers.
The code running SQL queries is pretty simple:
private List<values> GetItemsFromDB(string queryString, SqlParameter[] sqlParams)
{
var listOfItems = new List<Item>();
using (SqlConnection connection = new SqlConnection(_provider.ConnectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
try
{
connection.Open();
command.Parameters.AddRange(sqlParams);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
var item = new Item()
{
Id = Convert.ToInt64(reader["Id"]),
SerializedConfigItem = reader["SerializedItem"] != DBNull.Value
? reader["SerializedItem"].ToString()
: null,
SerializedItem2 = reader["SerializedItem2"] != DBNull.Value
? reader["SerializedItem2"].ToString()
: null,
Created = reader["Created"] != DBNull.Value
? Convert.ToDateTime(reader["Created"])
: DateTime.MinValue
};
listOfItems.Add(item);
}
reader.Close();
}
catch (Exception ex)
{
_logHandler.Error(ex.Message, "Error while trying to get items from DB");
}
finally
{
connection.Close();
}
return listOfItems;
}
}
private long WriteItemToDb(string queryString, SqlParameter[] sqlParams)
{
long id = 0;
using (SqlConnection connection = new SqlConnection(_provider.ConnectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
try
{
connection.Open();
command.Parameters.AddRange(sqlParams);
var obj = command.ExecuteScalar();
id = Convert.ToInt64(obj);
}
catch (Exception ex)
{
_logHandler.Error(ex.Message, "Error while trying to insert/update/delete items to DB");
}
finally
{
connection.Close();
}
return id;
}
}
Below are some of the different error messages we get randomly and intermittently:
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A non-recoverable error occurred during a database lookup.)"
"The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))"
"A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The handle is invalid.)"
"A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The handle is invalid.)"
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 9 - Associating port with I/O completion mechanism failed)"