Skip to content
Fix Code Error

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

March 13, 2021 by Code Error
Posted By: Anonymous

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?

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. 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. 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. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:

[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): 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): 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


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:

  1. using Application["OnlineUsers"] = 0;
  2. the other one using database

So, for method #2 I reset all OnlineUsers at Application_Start. There are over 482,751 records in that table.

Solution

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. 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

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.

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.

Answered By: Anonymous

Related Articles

  • Problems Installing CRA & NextJS from NPM…
  • Detect if Visual C++ Redistributable for Visual…
  • npm ERR! fetch failed status code 502
  • jQuery Mobile: document ready vs. page events
  • Obtain most recent value for based on index in a…
  • How to solve Internal Server Error in Next.Js?
  • unable to deploy next js to azure
  • useEffect Error: Minified React error #321 (GTM…
  • GLYPHICONS - bootstrap icon font hex value
  • Get operating system info
  • How to avoid a System.Runtime.InteropServices.COMException?
  • How to get main JQuery Mobile page to display after…
  • Rails wrong number of arguments error when…
  • How to download Xcode DMG or XIP file?
  • Throw HttpResponseException or return…
  • Reduce array according to grouping condition in reactjs
  • How can I find the product GUID of an installed MSI setup?
  • SMTP error 554
  • React Multi-level push menu SCSS Back button not working
  • For-loop vs while loop in R
  • Why call git branch --unset-upstream to fixup?
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • "The system cannot find the file specified"
  • Logging best practices
  • Comparison between Corona, Phonegap, Titanium
  • How to highlight border color of input when on…
  • Git - Pushing code to two remotes
  • Download a file with Android, and showing the…
  • How can I resolve Web Component Testing error?
  • java.sql.SQLException: - ORA-01000: maximum open…
  • What are the undocumented features and limitations…
  • How can I solve a connection pool problem between…
  • Error: the entity type requires a primary key
  • Could not load file or assembly…
  • How can I create an array from number and add some…
  • android studio 0.4.2: Gradle project sync failed error
  • How to change Windows 10 interface language on…
  • Could not load file or assembly 'Newtonsoft.Json' or…
  • How to create a temporary table in SSIS control flow…
  • modal View controllers - how to display and dismiss
  • How can I find the location of origin/master in git,…
  • Wordpress - add woocommerce billing_phone field into…
  • ember: understand errors
  • ExecuteReader requires an open and available…
  • How to use java.net.URLConnection to fire and handle…
  • How to download and save an image in Android
  • Fix top buttons on scroll of list below
  • Download & Install Xcode version without Premium…
  • How to connect a Windows Mobile PDA to Windows 10
  • Best way to do multi-row insert in Oracle?
  • The definitive guide to form-based website authentication
  • How can I throw CHECKED exceptions from inside Java…
  • Nested ng-repeat
  • What is a NullReferenceException, and how do I fix it?
  • getaddrinfo: nodename nor servname provided, or not known
  • laravel vuejs/axios put request Formdata is empty
  • How do I rename both a Git local and remote branch name?
  • Do you (really) write exception safe code?
  • Entity Framework Timeouts
  • Jetty server throws idle timeout for REST calls
  • Vagrant error : Failed to mount folders in Linux guest
  • jquery mobile require.js and backbone
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • Apache reverse-proxy to NodeJS WebSocket Server
  • problem with client server unix domain stream…
  • Name [jdbc/mydb] is not bound in this Context
  • Multipart File Upload Using Spring Rest Template +…
  • VUE Error when run test unit
  • Confused about the Visitor Design Pattern
  • (Mac) -bash: __git_ps1: command not found
  • Persistent invalid graphics state error when using ggplot2
  • How can I not close the connection due to a…
  • Python scrape JS data
  • "An exception occurred while processing your…
  • How can I sort a list that inside a map in Java?
  • Start redis-server with config file
  • ASP.NET Web Site or ASP.NET Web Application?
  • Flatten points into SVG polyline Polymer
  • “tag already exists in the remote" error after…
  • Remote end closed connection without response
  • MySQL database is not receiving any data in PHP
  • Modulus operator c# example
  • How can I test my Dao method with Mockito If I get…
  • Python File Error: unpack requires a buffer of 16 bytes
  • BigQuery: user metadata described by start date and…
  • ExpressJS How to structure an application?
  • How to obtain the start time and end time of a day?
  • Your configuration specifies to merge with the from…
  • Smart way to truncate long strings
  • ImproperlyConfigured: You must either define the…
  • Backbone.js and jQueryMobile routing without hack or…
  • Why do I get an Unhandled Promise Rejection with…
  • Login failed for user 'DOMAINMACHINENAME$'
  • Unable to connect to SQL Server instance remotely
  • javax.faces.application.ViewExpiredException: View…
  • Best Timer for using in a Windows service
  • Download file from an ASP.NET Web API method using AngularJS
  • Sending an HTTP POST request on iOS
  • How can I create a horizontal bar chart in R that is…
  • Repository access denied. access via a deployment…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Python string.replace regular expression

Next Post:

Remove all special characters from a string

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error