Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated

后端 未结 20 2199
臣服心动
臣服心动 2020-11-22 10:23

I have many users on my web site (20000-60000 per day), which is a download site for mobile files. I have remote access to my server (windows server 2008-R2).
I\'ve

相关标签:
20条回答
  • 2020-11-22 10:48

    In your code where you run the stored procedure you should have something like this:

    SqlCommand c = new SqlCommand(...)
    //...
    

    Add such a line of code:

    c.CommandTimeout = 0;
    

    This will wait as much time as needed for the operation to complete.

    0 讨论(0)
  • 2020-11-22 10:49

    We've had hard times on Timeout expired/max pool reached Sqlexception. As a workarround and to prevent restarting the server or the service we modify the MAX SERVER MEMORY variable in SQL Server (either through SQL Managment Studio or T-SQL):

    DECLARE @maxMem INT = 3000 --Max. memory for SQL Server instance in MB
    EXEC sp_configure 'show advanced options', 1
    RECONFIGURE
    

    This temporarily fixes the issue until it happens again. In our case we suspect that it has to do with connection leaks at app level.

    0 讨论(0)
  • 2020-11-22 10:50

    TLDR:

    1. Rebooting both application and DB servers is the quickest fix where data volume, network settings and code haven't changed. We always do so as a rule
    2. May be indicator of failing hard-drive that needs replacement - check system notifications

    I have often encountered this error for various reasons and have had various solutions, including:

    1. refactoring my code to use SqlBulkCopy
    2. increasing Timeout values, as stated in various answers or checking for underlying causes (may not be data related)
    3. Connection Timeout (Default 15s) - How long it takes to wait for a connection to be established with the SQL server before terminating - TCP/PORT related - can go through a troubleshooting checklist (very handy MSDN article)
    4. Command Timeout (Default 30s) - How long it takes to wait for the execution of a query - Query execution/network traffic related - also has a troubleshooting process (another very handy MSDN article)
    5. Rebooting of the server(s) - both application & DB Server (if separate) - where code and data haven't changed, environment must have changed - First thing you must do. Typically caused by patches (operating system, .Net Framework or SQL Server patches or updates). Particularly if timeout exception appears as below (even if we do not use Azure):
      • System.Data.Entity.Core.EntityException: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy. ---> System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.) ---> System.ComponentModel.Win32Exception: The semaphore timeout period has expired
    0 讨论(0)
  • 2020-11-22 10:51

    I have issue with large calculation in sp_foo that take large time so i fixed
    with this little bit code

    public partial class FooEntities : DbContext
    {
       public FooEntities()
             : base("name=FooEntities")
        {
            this.Configuration.LazyLoadingEnabled = false;
    
            // Get the ObjectContext related to this DbContext
            var objectContext = (this as IObjectContextAdapter).ObjectContext;
    
            // Sets the command timeout for all the commands
            objectContext.CommandTimeout = 380;
        }
    
    0 讨论(0)
  • 2020-11-22 10:53

    You could set the CommandTimeout property of the SQL Command to allow for the long running SQL transaction.

    You might also need to look at the SQL Query that is causing the timeout.

    0 讨论(0)
  • 2020-11-22 10:53

    I encountered this error recently and after some brief investigation, found the cause to be that we were running out of space on the disk holding the database (less than 1GB).

    As soon as I moved out the database files (.mdf and .ldf) to another disk on the same server (with lots more space), the same page (running the query) that had timed-out loaded within three seconds.

    One other thing to investigate, while trying to resolve this error, is the size of the database log files. Your log files just might need to be shrunk.

    0 讨论(0)
提交回复
热议问题