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

后端 未结 20 2198
臣服心动
臣服心动 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:39

    Timeout expired because the sql query is taking more time than you set in sqlCommand.CommandTimeout property.

    Obviously you can increase CommandTimeout to solve this issue but before doing that you must optimize your query by adding index. If you run your query in Sql server management studio including actual execution plan then Sql server management studio will suggest you proper index. Most of the case you will get rid of timeout issue if you can optimize your query.

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

    You have to set CommandTimeout attribute. You can set the CommandTimeout attribute in DbContext child class.

    public partial class StudentDatabaseEntities : DbContext
    {
        public StudentDatabaseEntities()
            : base("name=StudentDatabaseEntities")
        {
            this.Database.CommandTimeout = 180;
        }
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
    
        public virtual DbSet<StudentDbTable> StudentDbTables { get; set; }
    }
    
    0 讨论(0)
  • 2020-11-22 10:41

    @SilverLight.. This is clearly an issue with a Database object. It can be a badly written query, or missing indexes. But as of now I won't suggest you to increase the timeout without investigating the issue with your Database objects

    NovinMedia.Data.DbObject.RunProcedure(String storedProcName, IDataParameter[] parameters, Int32& rowsAffected) +209
    

    Put a breakpoint on this line of code to findout the procedure name and then optimise the procedure by looking at its execution plan.

    I cannot help you more till the time you post details about the stored procedure.

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

    I had the same issue and resolved by adding "Connection Time" value in web.config file. locate the connectionStrings and add Connection Timeout=3600"

    here is the sample

      <connectionStrings>
        <add name="MyConn" providerName="System.Data.SqlClient" connectionString="Data Source=MySQLServer;Initial Catalog=MyDB;User ID=sa;Password=123;Connection Timeout=3600" />
      </connectionStrings>
    
    0 讨论(0)
  • 2020-11-22 10:46

    Also you need to check if individual record is not getting updated in the logic because with update trigger in the place causes time out error too.

    So, the solution is to make sure you perform bulk update after the loop/cursor instead of one record at a time in the loop.

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

    Also make sure you just don't have a pending transaction. :)

    I was doing some tests around and began a transaction to be safe but never closed it. I wish the error would have been more explicit but oh well!

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