Execution Timeout Expired Error with UPS API Request in SQL Server 2019 Backend

Vinith 45 Reputation points
2024-06-21T07:34:58+00:00

Hello everyone,

I'm encountering an issue with a web backend application that uses SQL Server 2019. We send a request to the UPS API, but it fails, and the application error log shows the following message:

LOGGER Error: 0 : 6/14/2024 2:45:38 PM : System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

A transaction that was started in a MARS batch is still active at the end of the batch. The transaction is rolled back.

Operation cancelled by user.

The statement has been terminated.

The statement has been terminated.

The statement has been terminated.

The statement has been terminated.

The statement has been terminated. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

Environment Details:

  • SQL Server 2019
  • Web backend application in C#
  • Connecting to UPS API

Troubleshooting Steps Taken:

  1. Verified there are no SQL connection dropouts, blocks, or locks.
  2. Checked for network latency issues.
  3. Ensured SQL queries are optimized, and indexes are properly set.

Despite these measures, the error persists. Here are some additional details that might help:

  • Query Complexity: The query involved in the UPS API request is not overly complex, but it does join several tables and includes a few WHERE clauses.
  • Resource Utilization: Monitoring indicates no excessive CPU or memory usage on the SQL Server.
  • Timeout Settings: It's already Unlimited

Questions:

  1. Are there any specific settings in SQL Server 2019 or .NET's SqlClient that could help prevent these timeout issues?
  2. Could the use of MARS (Multiple Active Result Sets) be causing these problems? If so, how can I mitigate this?
  3. What additional steps can I take to diagnose and resolve this timeout error?

Any advice or pointers would be greatly appreciated. Thank you!

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,207 questions
{count} votes

Accepted answer
  1. LucyChenMSFT-4874 2,825 Reputation points
    2024-06-24T01:56:38.4833333+00:00

    Hi @Vinith,

    Thank you for reaching out and welcome to Microsoft Q&A.

    You've tried to increase the connection timeout, but it was still this exception. I found this article and it was found that incorrect caching of statistics and/or query plans for the database could also cause this issue. Could you please try this query:

    exec sp_updatestats
    

    Updating statistics ensures that queries are compiled with the latest statistics.

    If the problem is not solved after the execution, please try this:

    dbcc freeproccache
    

    Deletes all elements in the plan cache, removes a specific plan from the plan cache by specifying a plan handle or SQL handle, or deletes all cache entries associated with a specified resource pool.

    It can be determined that the issue appears because the execution plan of the in-memory cache is wrong or not optimal. This is the official document, hope this can help you well.

    Feel free to share your issue here if you have any confusions.

    Best regards,

    Lucy Chen


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    https://docs.microsoft.com/en-us/answers/support/email-notifications


1 additional answer

Sort by: Most helpful
  1. Olaf Helper 42,761 Reputation points
    2024-06-21T07:43:19.1066667+00:00

    Regarding 1): SQL Server don't terminate queries on it's own (beside deadlock victim), it's a clinet setting, see SqlCommand.CommandTimeout Property.; defualt is 30 seconds.

    But that will only "hide" the problem and don't solve it. Better optimize table/index/query design.

    1 person found this answer helpful.