问题描述
我有我的网站(20000-60000每天),这是一个用于移动文件的下载网站许多用户。我有我的服务器(Windows Server 2008 R2)远程访问。我收到服务器不可用错误之前,但我现在看到连接超时错误。我不熟悉这个 - 为什么会出现这种问题如何解决呢?
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 received "Server is unavailable" errors before, but am now seeing a connection timeout error. I'm not familiar with this - why does it occur and how can I fix it?
完整的错误是如下:
在'/'应用程序的服务器错误。超时已过期。超时时间
操作完成之前经过或该服务器不是
响应。该语句已终止。说明:
当前Web的执行过程中发生未处理的异常
请求。请检查堆栈跟踪有关的详细信息
错误以及它起源于code。
异常详细信息:System.Data.SqlClient.SqlException:超时
过期。超时时间已过的完成前
操作或服务器没有响应。该语句已
终止。
Exception Details: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated.
源错误:
的执行过程中生成了未处理的异常
当前Web请求。有关的起源和位置信息
除了可以使用异常堆栈跟踪下面来识别。
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
堆栈跟踪:
[SQLEXCEPTION(0x80131904):超时过期。超时时间
操作完成之前经过或该服务器不是
响应。该语句已终止。]结果
System.Data.SqlClient.SqlConnection.OnError(SqlException异常,
布尔breakConnection)404结果
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()412结果
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
的SqlCommand cmdHandler,SqlDataReader的数据流,
BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject
stateObj)1363结果
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader的DS,
RunBehavior runBehavior,字符串resetOptionsString)6387741结果
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(的CommandBehavior
cmdBehavior,RunBehavior runBehavior,布尔returnStream,布尔
异步)6389442结果
System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior
cmdBehavior,RunBehavior runBehavior,布尔returnStream,字符串
方法,DbAsyncResult结果)538结果
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
结果,字符串methodName中,布尔sendToPipe)+689结果
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()327结果
NovinMedia.Data.DbObject.RunProcedure(字符串storedProcName,
的IDataParameter []参数的Int32&安培;的RowsAffected)+ 209结果
DataLayer.OnlineUsers.Update_SessionEnd_And_Online(对象Session_End中,
布尔在线)440结果
NiceFileExplorer.Global.Application_Start(对象发件人,EventArgs的发送)
+163
[SqlException (0x80131904): Timeout expired. 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.TdsParser.ThrowExceptionAndWarning() +412
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.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6389442
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.ExecuteNonQuery() +327
NovinMedia.Data.DbObject.RunProcedure(String storedProcName, IDataParameter[] parameters, Int32& rowsAffected) +209
DataLayer.OnlineUsers.Update_SessionEnd_And_Online(Object Session_End, Boolean Online) +440
NiceFileExplorer.Global.Application_Start(Object sender, EventArgs e) +163
[HttpException(0x80004005的):超时过期。超时时间
操作完成之前经过或该服务器不是
响应。该语句已终止。]结果
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext的
背景下,HttpApplication的应用程序)4052053结果
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr的
appContext,HttpContext的背景下,MethodInfo的[]处理程序)+191结果
System.Web.HttpApplication.InitSpecial(HttpApplicationState状态,
MethodInfo的[]处理器,IntPtr的appContext,HttpContext的背景下)+352结果
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr的
appContext,HttpContext的背景下)407结果
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr的
appContext)+375
[HttpException (0x80004005): Timeout expired. 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.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +352
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375
[HttpException(0x80004005的):超时过期。超时时间
操作完成之前经过或该服务器不是
响应。该语句已终止。]结果
System.Web.HttpRuntime.FirstRequestInit(HttpContext的背景下)11686928
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext的背景下)
+141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
WR,HttpContext的背景下)4863749
[HttpException (0x80004005): Timeout expired. 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
修改应答后:结果
我的的Application_Start
在的Global.asax
是象下面这样:
EDIT AFTER ANSWERS:
my Application_Start
in Global.asax
is like below:
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:
- 使用
应用[OnlineUsers] = 0;
- 使用数据库中的另一个
所以,方法#2重置在的Application_Start
所有OnlineUsers。有超过482751条记录在该表中。
So, for method #2 I reset all OnlineUsers at Application_Start
. There are over 482,751 records in that table.
推荐答案
看起来你有时间比正常情况下长的查询。
从你的堆栈跟踪和你的code,你应该能够确定什么查询即是。
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;
- 有一个僵局的地方
- 数据库的统计数据和/或查询计划缓存是不正确
- 查询是过于复杂并且需要调整
一个僵局可能很难解决,但它很容易,以确定是否是这种情况。连接到使用SQL Server Management Studio中的数据库。在左窗格中的服务器节点上单击鼠标右键,选择的活动监视器的。看看正在运行的进程。
通常,大多数将被闲置或跑步。当出现问题时,你可以通过进程状态识别任何阻塞的进程。如果你在这个过程单击鼠标右键,选择的详情的它会告诉你该进程执行的最后一个查询。
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. In the left pane right-click on the server node and select 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
您不应该这样做,当你的服务器负载过大,因为它会招致临时大服务表现击中第一次执行时,所有存储的特效和查询重新编译。
然而,由于你的国家出现问题的有时的,和堆栈跟踪表明应用程序启动时,我想你正在运行一个查询,只是偶尔运行。你可能会通过强制的SQL Server不重用previous查询计划更好。请参见关于如何做到这一点的详细信息。
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. See this answer for details on how to do that.
我已经谈到了第三个问题,但是你可以很容易地判断手动执行查询,例如使用SQL Server Management Studio中查询是否需要调整。如果查询时间过长完成,即使复位后统计,你可能需要调整它。对于与帮助,您应当发布准确的查询中的新问题。
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. 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.
这篇关于超时已过期。完成操作或服务器之前已超时期间没有响应。该语句已终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!