Srinivas
Srinivas

Reputation: 11

Database timeout in Azure SQL

We have a .Net Core API accessing Azure SQL (Gen5, 4 vCores)

Since quite some time, the API keeps throwing below exception for a specific READ operation

Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

The READ operation has code to read rows of data and convert an XML column into a specific output format. Most of the read operation extracts hardly 4-5 rows @ a time. The tables involved in the query have ~ 500,000 rows

We are clueless on Root Cause of this issue.

Any hints on where to start looking @ for root cause?

Any pointer would be highly appreciated.

NOTE : Connection string has following settings, apart from others

MultipleActiveResultSets=True;Connection Timeout=60

Overall code looks something like this.

HINT: The above timeout exception comes @ ConvertHistory, when the 2nd table is being read.

HttpGet]
public async Task<IEnumerable<SalesOrders>> GetNewSalesOrders()
{
    var SalesOrders = await _db.SalesOrders.Where(o => o.IsImported == false).OrderBy(o => o.ID).ToListAsync();
    var orders = new List<SalesOrder>();

   foreach (var so in SalesOrders)
   {
    var order = ConvertSalesOrder(so);
    orders.Add(order);
   }

   return orders;
}

private SalesOrder ConvertSalesOrder(SalesOrder o)
{
    var newOrder = new SalesOrder();    
    var oXml = o.XMLContent.LoadFromXMLString<SalesOrder>();    
    ... 
    newOrder.BusinessUnit = oXml.BusinessUnit;  
    var history = ConvertHistory(o.ID);     
    newOrder.history = history; 
    
    return  newOrder;
}

private SalesOrderHistory[] ConvertHistory(string id)
{
    var history = _db.OrderHistory.Where(o => o.ID == id);
    ...
}

Upvotes: 1

Views: 5191

Answers (1)

Pratik Lad
Pratik Lad

Reputation: 8291

Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

From Microsoft Document,

You will get this error in both conditions Connection timeout or Query or command timeout. first identify it from call stack of the error messages.

If you found it as a connection issue you can either Increase connection timeout parameter. if you are still getting same error, it is causing due to a network issue.

from information that you provided It is Query or command timeout error to work around this error you can set CommandTimeout for query or command

    command.CommandTimeout = 10;

The default timeout value is 30 seconds, the query will continue to run until it is finished if the time-out value is set to 0 (no time limit).

For more information refer Troubleshoot query time-out errors provided by Microsoft.

Upvotes: 2

Related Questions