简体   繁体   English

超时已过。 在操作完成之前超时时间已过或服务器没有响应。 该语句已终止

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

I have many users on my web site (20000-60000 per day), which is a download site for mobile files.我的网站上有很多用户(每天 20000-60000),这是一个移动文件的下载网站。 I have remote access to my server (windows server 2008-R2).我可以远程访问我的服务器(Windows 服务器 2008-R2)。
I've received "Server is unavailable" errors before, but I am now seeing a connection timeout error.我之前收到过“服务器不可用”错误,但现在我看到了连接超时错误。
I'm not familiar with this - why does it occur and how can I fix it?我对此不熟悉 - 为什么会发生,我该如何解决?

The full error is below:完整的错误如下:

Server Error in '/' Application. “/”应用程序中的服务器错误。 Timeout expired.超时已过。 The timeout period elapsed prior to completion of the operation or the server is not responding.在操作完成之前超时时间已过或服务器没有响应。 The statement has been terminated.该语句已终止。 Description: An unhandled exception occurred during the execution of the current web request.说明:执行当前 Web 请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

Exception Details: System.Data.SqlClient.SqlException: Timeout expired.异常详细信息:System.Data.SqlClient.SqlException:超时已过期。 The timeout period elapsed prior to completion of the operation or the server is not responding.在操作完成之前超时时间已过或服务器没有响应。 The statement has been terminated.该语句已终止。

Source Error:源错误:

An unhandled exception was generated during the execution of the current web request.在执行当前 Web 请求期间生成了未处理的异常。 Information regarding the origin and location of the exception can be identified using the exception stack trace below.可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

Stack Trace:堆栈跟踪:

[SqlException (0x80131904): Timeout expired. [SqlException (0x80131904): 超时。 The timeout period elapsed prior to completion of the operation or the server is not responding.在操作完成之前超时时间已过或服务器没有响应。 The statement has been terminated.]该语句已终止。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404 System.Data.SqlClient.SqlConnection.OnError(SqlException 异常,布尔 breakConnection)+404
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)+1363
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6387741 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6387741
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6389442 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔返回流,布尔异步)+6389442
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +538 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +538
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +689 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult 结果,String methodName,Boolean sendToPipe) +689
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +327 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +327
NovinMedia.Data.DbObject.RunProcedure(String storedProcName, IDataParameter[] parameters, Int32& rowsAffected) +209 NovinMedia.Data.DbObject.RunProcedure(String storedProcName, IDataParameter[] 参数, Int32& rowsAffected) +209
DataLayer.OnlineUsers.Update_SessionEnd_And_Online(Object Session_End, Boolean Online) +440 DataLayer.OnlineUsers.Update_SessionEnd_And_Online(Object Session_End, Boolean Online) +440
NiceFileExplorer.Global.Application_Start(Object sender, EventArgs e) +163 NiceFileExplorer.Global.Application_Start(对象发送者,EventArgs e)+163

[HttpException (0x80004005): Timeout expired. [HttpException(0x80004005):超时。 The timeout period elapsed prior to completion of the operation or the server is not responding.在操作完成之前超时时间已过或服务器没有响应。 The statement has been terminated.]该语句已终止。]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +4052053 System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext 上下文,HttpApplication 应用程序)+405205​​3
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext 上下文,MethodInfo[] 处理程序)+191
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +352 System.Web.HttpApplication.InitSpecial(HttpApplicationState 状态,MethodInfo[] 处理程序,IntPtr appContext,HttpContext 上下文)+352
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375

[HttpException (0x80004005): Timeout expired. [HttpException(0x80004005):超时。 The timeout period elapsed prior to completion of the operation or the server is not responding.在操作完成之前超时时间已过或服务器没有响应。 The statement has been terminated.]该语句已终止。]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11686928 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4863749 System.Web.HttpRuntime.FirstRequestInit(HttpContext 上下文)+11686928 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext 上下文)+141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest WR,HttpContext 上下文)+4863749


EDIT AFTER ANSWERS:回答后编辑:
my Application_Start in Global.asax is like below:我在Global.asax中的Application_Start如下所示:

protected void Application_Start(object sender, EventArgs e)
{
    Application["OnlineUsers"] = 0;

    OnlineUsers.Update_SessionEnd_And_Online(
        DateTime.Now,
        false);

    AddTask("DoStuff", 10);
}

The stored procedure being called is:被调用的存储过程是:

ALTER Procedure [dbo].[sp_OnlineUsers_Update_SessionEnd_And_Online]
    @Session_End datetime,
    @Online bit
As
Begin
    Update OnlineUsers
    SET
        [Session_End] = @Session_End,
        [Online] = @Online

End

I have two methods for getting online users:我有两种获取在线用户的方法:

  1. using Application["OnlineUsers"] = 0;使用Application["OnlineUsers"] = 0;
  2. the other one using database另一个使用数据库

So, for method #2 I reset all OnlineUsers at Application_Start .因此,对于方法 #2,我在Application_Start重置了所有 OnlineUsers。 There are over 482,751 records in that table.该表中有超过 482,751 条记录。

Looks like you have a query that is taking longer than it should.看起来您的查询花费的时间比应有的要长。 From your stack trace and your code you should be able to determine exactly what query that is.从您的堆栈跟踪和代码中,您应该能够准确确定是什么查询。

This type of timeout can have three causes;这种类型的超时可能有三个原因;

  1. There's a deadlock somewhere某处出现了僵局
  2. The database's statistics and/or query plan cache are incorrect数据库的统计信息和/或查询计划缓存不正确
  3. The query is too complex and needs to be tuned查询太复杂,需要调优

A deadlock can be difficult to fix, but it's easy to determine whether that is the case.死锁可能很难修复,但很容易确定是否是这种情况。 Connect to your database with Sql Server Management Studio.使用 Sql Server Management Studio 连接到您的数据库。 In the left pane right-click on the server node and select Activity Monitor .在左窗格中,右键单击服务器节点并选择Activity Monitor Take a look at the running processes.查看正在运行的进程。 Normally most will be idle or running.通常大多数将处于空闲或运行状态。 When the problem occurs you can identify any blocked process by the process state.当问题发生时,您可以通过进程状态识别任何阻塞的进程。 If you right-click on the process and select details it'll show you the last query executed by the process.如果您右键单击该流程并选择详细信息,它将向您显示该流程执行的最后一个查询。

The second issue will cause the database to use a sub-optimal query plan.第二个问题将导致数据库使用次优查询计划。 It can be resolved by clearing the statistics:可以通过清除统计信息来解决:

exec sp_updatestats

If that doesn't work you could also try如果这不起作用,您也可以尝试

dbcc freeproccache

You should not do this when your server is under heavy load because it will temporarily incur a big performace hit as all stored procs and queries are recompiled when first executed.当你的服务器负载很重时你不应该这样做,因为它会暂时产生很大的性能损失,因为所有存储的过程和查询在第一次执行时都会重新编译。 However, since you state the issue occurs sometimes , and the stack trace indicates your application is starting up, I think you're running a query that is only run on occasionally.但是,由于您声明问题有时会发生,并且堆栈跟踪表明您的应用程序正在启动,我认为您正在运行一个仅偶尔运行的查询。 You may be better off by forcing SQL Server not to reuse a previous query plan.强制 SQL Server 不重用以前的查询计划可能会更好。 See this answer for details on how to do that.有关如何执行此操作的详细信息,请参阅此答案

I've already touched on the third issue, but you can easily determine whether the query needs tuning by executing the query manually, for example using Sql Server Management Studio.我已经谈到了第三个问题,但是您可以通过手动执行查询来轻松确定查询是否需要调整,例如使用 Sql Server Management Studio。 If the query takes too long to complete, even after resetting the statistics you'll probably need to tune it.如果查询需要很长时间才能完成,即使在重置统计信息之后,您也可能需要对其进行调整。 For help with that, you should post the exact query in a new question.如需帮助,您应该在新问题中发布确切的查询。

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.这将等待操作完成所需的尽可能多的时间。

You could set the CommandTimeout property of the SQL Command to allow for the long running SQL transaction.您可以设置 SQL 命令的CommandTimeout属性以允许长时间运行的 SQL 事务。

You might also need to look at the SQL Query that is causing the timeout.您可能还需要查看导致超时的 SQL 查询。

Maybe it will be useful for somebody.也许它对某人有用。 I faced with the same problem and in my case the reason was the SqlConnection was opened and not disposed in the method that I called in loop with about 2500 iterations.我遇到了同样的问题,在我的情况下,原因是 SqlConnection 已打开并且没有在我以大约 2500 次迭代循环调用的方法中进行处理。 Connection pool was exhausted.连接池已用尽。 Proper disposing solved the problem.适当的处理解决了这个问题。

I had the same issue and resolved by adding "Connection Time" value in web.config file.我遇到了同样的问题,并通过在 web.config 文件中添加“连接时间”值来解决。 locate the connectionStrings and add Connection Timeout=3600"找到 connectionStrings 并添加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>

While all the earlier responses address the issue they did not cover all cases.尽管所有较早的答复都解决了该问题,但它们并未涵盖所有情况。

Microsoft has acknowledged the issue and fixed it in 2011 for supported operating systems, so if you get the stack trace like:微软已经承认了这个问题,并在 2011 年针对支持的操作系统修复了它,所以如果你得到如下堆栈跟踪:

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)

you may need to update your .NET assemblies.您可能需要更新您的 .NET 程序集。

This issue occurs because of an error in the connection-retry algorithm for mirrored databases.出现此问题的原因是镜像数据库的连接重试算法中的错误。

When the retry-algorithm is used, the data provider waits for the first read (SniReadSync) call to finish.使用重试算法时,数据提供程序会等待第一次读取 (SniReadSync) 调用完成。 The call is sent to the back-end computer that is running SQL Server, and the waiting time is calculated by multiplying the connection time-out value by 0.08.调用被发送到运行 SQL Server 的后端计算机,等待时间的计算方法是将连接超时值乘以 0.08。 However, the data provider incorrectly sets a connection to a doomed state if a response is slow and if the first SniReadSync call is not completed before the waiting time expires.但是,如果响应缓慢并且在等待时间到期之前未完成第一个 SniReadSync 调用,则数据提供程序错误地将连接设置为注定状态。

See KB 2605597 for details有关详细信息,请参阅 KB 2605597

https://support.microsoft.com/kb/2605597 https://support.microsoft.com/kb/2605597

You have to set CommandTimeout attribute.您必须设置 CommandTimeout 属性。 You can set the CommandTimeout attribute in DbContext child class.您可以在 DbContext 子类中设置 CommandTimeout 属性。

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; }
}

I faced same problem worked on it around 3 days.我在大约 3 天的时间里遇到了同样的问题。 I noticed as our number of records are not much our senior developer keeps 2 images and Fingerprint in database.我注意到我们的记录数量不多,我们的高级开发人员在数据库中保留了 2 张图像和指纹。 When I try to fetch this hex values it taking long time, I calculate average time to execute my procedure its around 38 seconds.当我尝试获取这个需要很长时间的十六进制值时,我计算执行我的程序的平均时间大约为 38 秒。 The default commandtimeout is 30 seconds so its less than average time required to run my stored procedure.默认命令超时为 30 秒,因此它比运行我的存储过程所需的平均时间要短。 I set my commandtimeout like below我将我的命令超时设置如下

cmd.CommandTimeout = 50

and its working fine but sometimes if your query takes more than 50 seconds it will prompt same error.它工作正常,但有时如果您的查询需要超过 50 秒,它会提示相同的错误。

If you are using ASP.NET Core with the Startup.cs convention, you can access and set the query command timeout option like this:如果您使用带有Startup.cs约定的 ASP.NET Core,则可以访问和设置查询命令超时选项,如下所示:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContextPool<MyDbContext>(_ =>
    {
        _.UseSqlServer(Configuration.GetConnectionString("MyConnectionString"), options => 
        {
            options.CommandTimeout(180); // 3 minutes
        });
    });
}

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).我最近遇到了这个错误,经过一些简短的调查,发现原因是我们保存数据库的磁盘空间不足(小于 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.一旦我将数据库文件(.mdf 和 .ldf)移出到同一台服务器上的另一个磁盘(有更多空间),在三秒钟内就会加载超时的同一页面(运行查询)。

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.您的日志文件可能只是需要缩小。

Default timeout is 15 seconds, to change that, 0 is unlimited, any other number is the number of seconds.默认超时为 15 秒,要更改它,0 是无限的,任何其他数字都是秒数。

In Code在代码中

using (SqlCommand sqlCmd = new SqlCommand(sqlQueryString, sqlConnection))
   {
      sqlCmd.CommandTimeout = 0; // 0 = give it as much time as it needs to complete
      ...
    }

In Your Web.Config, "Command Timeout=0;"在您的 Web.Config 中,“命令超时 = 0;” do not time out, or as below 1 hour (3600 seconds)不要超时,或低于 1 小时(3600 秒)

  <add name="ConnectionString" connectionString="Data Source=ServerName;User ID=UserName;Password=Password;Command Timeout=3600;" providerName="System.Data.SqlClient" />

I have issue with large calculation in sp_foo that take large time so i fixed我对 sp_foo 中的大型计算有问题,这需要很长时间,所以我修复了
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;
    }

@SilverLight.. This is clearly an issue with a Database object. @SilverLight .. 这显然是数据库对象的问题。 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.在您发布有关存储过程的详细信息之前,我无法为您提供更多帮助。

try尝试

EXEC SP_CONFIGURE 'remote query timeout', 1800
reconfigure
EXEC sp_configure

EXEC SP_CONFIGURE 'show advanced options', 1
reconfigure
EXEC sp_configure

EXEC SP_CONFIGURE 'remote query timeout', 1800
reconfigure
EXEC sp_configure

then rebuild your index然后重建你的索引

TLDR : 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重构我的代码以使用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)连接超时(默认 15 秒)——在终止之前等待与 SQL 服务器建立连接需要多长时间——与 TCP/PORT 相关——可以通过故障排除清单(非常方便的 MSDN 文章)
  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)命令超时(默认 30 秒) - 等待执行查询需要多长时间 - 查询执行/网络流量相关 - 也有故障排除过程(另一篇非常方便的 MSDN 文章)
  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).通常由补丁(操作系统、.Net Framework 或 SQL Server 补丁或更新)引起。 Particularly if timeout exception appears as below (even if we do not use Azure):特别是如果出现如下超时异常(即使我们不使用 Azure):
    • System.Data.Entity.Core.EntityException: An exception has been raised that is likely due to a transient failure. System.Data.Entity.Core.EntityException:引发了一个异常,可能是由于暂时性故障。 If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy.如果要连接到 SQL Azure 数据库,请考虑使用 SqlAzureExecutionStrategy。 ---> System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. ---> System.Data.Entity.Core.EntityCommandExecutionException:执行命令定义时出错。 See the inner exception for details.有关详细信息,请参阅内部异常。 ---> System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. ---> System.Data.SqlClient.SqlException:从服务器接收结果时发生传输级错误。 (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.) ---> System.ComponentModel.Win32Exception: The semaphore timeout period has expired (提供者:TCP Provider,错误:0 - 信号量超时期限已过期。)---> System.ComponentModel.Win32Exception:信号量超时期限已过期

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!我希望错误会更明确,但是哦,好吧!

We recently upgraded to the NuGet version of SqlClient ( Microsoft.Data.SqlClient ) which contains a bug .我们最近升级到了包含错误的SqlClient ( Microsoft.Data.SqlClient ) 的 NuGet 版本 This bug was introduced during the lifetime of the 1.x cycle and has already been fixed.此错误是在 1.x 周期的生命周期中引入的,并且已经修复。 The fix will be available in the 2.0.0 release which is not available at the time of this writing.该修复程序将在 2.0.0 版本中提供,在撰写本文时该版本不可用。 A preview is available.可以预览。

You can inspect the details here: https://github.com/dotnet/SqlClient/issues/262您可以在此处查看详细信息: https ://github.com/dotnet/SqlClient/issues/262

I had this problem once and in my case was an uncommited transaction in SQL.我曾经遇到过这个问题,在我的情况下是 SQL 中的未提交事务。 After I commited, the problem went away.在我提交之后,问题就消失了。

Timeout expired because the sql query is taking more time than you set in sqlCommand.CommandTimeout property.超时已过期,因为 sql 查询花费的时间比您在 sqlCommand.CommandTimeout 属性中设置的时间长。

Obviously you can increase CommandTimeout to solve this issue but before doing that you must optimize your query by adding index.显然你可以增加 CommandTimeout 来解决这个问题,但在这样做之前你必须通过添加索引来优化你的查询。 If you run your query in Sql server management studio including actual execution plan then Sql server management studio will suggest you proper index.如果您在Sql server management studio中运行查询,包括实际执行计划,则Sql server management studio会建议您使用正确的索引。 Most of the case you will get rid of timeout issue if you can optimize your query.大多数情况下,如果您可以优化查询,您将摆脱超时问题。

We've had hard times on Timeout expired/max pool reached Sqlexception .我们在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):作为解决方法并防止重新启动服务器或服务,我们修改 SQL Server 中的MAX SERVER MEMORY变量(通过 SQL Managment Studio 或 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.在我们的案例中,我们怀疑它与应用程序级别的连接泄漏有关。

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.因此,解决方案是确保在循环/光标之后执行批量更新,而不是在循环中一次一条记录。

我遇到了这个问题,当我从ADO.Net转移到Dapper进行查询时,它就消失了。

As others have said, the problem might be related with a pending transaction.正如其他人所说,问题可能与待处理的交易有关。 In my case I had to send the DbTransaction variable as a parameter in the ExecuteScalar method for the procedure to be executed properly.在我的情况下,我必须将DbTransaction变量作为ExecuteScalar方法中的参数发送,以便正确执行该过程。

Before:前:

ExecuteScalar(command)

After:后:

ExecuteScalar(command, transaction)

In my case I used EntityFrameworkCore .就我而言,我使用了EntityFrameworkCore
Since the input I wanted to be processed exceeded the query limit this error came to me.由于我想要处理的输入超出了查询限制,这个错误出现在我身上。
The solution for my case was to split the data processing into chunks and by this approach I was able to fit within the limits.我的情况的解决方案是数据处理分成,通过这种方法,我能够适应限制。
Yes, it takes time, but at least it processes all of the input records.是的,这需要时间,但至少它会处理所有输入记录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 超时时间已到。 在操作完成之前超时或服务器没有响应。 在远程Windows .net上工作 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. working on remote windows .net '执行超时已过期。 在操作完成之前超时时间已过或服务器没有响应。 - 'Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.' 超时已过。 操作完成前超时时间已过或服务器未响应。 从数据库中获取记录时 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. While fetching records from database SQL Server异常:超时已过期。 操作完成之前经过的超时时间或服务器未响应 - SQL Server Exception:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding ExecuteQueryin linq:超时已过期。 操作完成之前经过的超时时间或服务器没有响应 - ExecuteQueryin linq :Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding Linq Count() 超时 - 执行超时已过期。 操作完成前超时时间已过或服务器未响应 - Linq Count() timing out -Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding 超时时间已到。 操作完成之前经过的超时时间或服务器未响应 - Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding 超时时间已到。 操作完成之前经过的超时时间或服务器未响应 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding 在sis中执行软件包会导致超时过期。 操作完成之前经过的超时时间或服务器未响应 - Execute package in ssis causes Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding 超时已过。 操作完成前超时时间已过或服务器未响应 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM