timeout exception in asp.net application - c#

I cannot figure out why I am getting timeout exception in asp.net application upon signing into application and when I restart my webserver I don't get timeout exception?
Environment:
Asp.net application(IIS webserver) and DB (Sql server)
both IIS and Sql server are on two different machines.
Sql server timeout:600 seconds
Webconfig setting:
<httpRuntime maxRequestLength="16384" executionTimeout="270"/>
<sessionState mode="InProc" cookieless="false" timeout="60" stateConnectionString="">
Thanks in advance.
Screenshot of error:

Try to add connection timeout in connection string as "Data Source=SQLSERVER;Initial Catalog=MYCATALOG;Integrated Security=True;Connection Timeout=1000".if again "The wait operation timed out" then it is likely you have a database call that took longer than expected. This could be due to any number of things:
Transient network problem
High SQL server load
Problem with SAN, RAID, or storage device
Deadlock or other form of multiprocess contention
You haven't shared enough information to troubleshoot. The way I would manage this would be to check for other occurrences of the problem and see if there is a pattern, e.g. if the problem occurs at a certain time of day.
Certainly increasing the timeout is not a bad idea (if it is currently set pretty low) and may resolve the problem in and of itself.

Related

How can a slow internet on client side be a reason for server time out exception in asp.net?

I have a .Net application up and running.
We have had a fluctuating connection yesterday. While testing in such scenarios we had received multiple server time out exception emails like below.
Server Time Out
Type : System.Web.HttpException, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Message : Request timed out.
Source :
Help link :
WebEventCode : 3001
ErrorCode : -2147467259
Data : System.Collections.ListDictionaryInternal
TargetSite :
HResult : -2147467259
Stack Trace : The stack trace is unavailable.
Additional Info:
IMPORTANT: Above exception occurred while doing a ajax post by a button placed with in update panel.
My question here is why would a slow internet on client side raise such server time out exception?
Isn't server timeout exception is related to such cases where server cannot execute the request in underlying time mention in HttpRuntime setting? May be due to some lengthy operation or some long database execution which takes longer than the time mentioned in setting under HttpRuntime.
If server is not able to connect to the client due to clients fluctuating internet, then Client Disconnected exception would be raised which we did yesterday. But I am not able to conclude the reason for this server timeout exception.
I already know that increasing the execution timeout will fix the issue, but I have to provide technical explanation for the reason as to why such exception of Server Timeout raised.
My best guess here is that the ajax request would be doing some continuous communication with server for executing of single request server and would raise timeout exception if it does not receives some required further communication messages due to client's bad internet. I have search over internet for the same to support my guess but in vain.
Also to provide environmental details, there is a load balancer serving the request.
Any help would be highly appreciated.
It is because (as you write) the connection of client to server is slow, so if the server (or client) sending data to this server, connection can´t handle it, so you get timeout error, because the data can´t been transfered in defined time.
You also write, that this is caused by sending Ajax request, so maybe try to increase execusion timeout in web configuration file (web.config):
<httpRuntime executionTimeout = "number(in seconds)"/>
More about executionTimeout here and here about Ajax requests.
Firstly, I think the cause of this error is because of execution time required by your application request connecting with the remote server is exceeding the currently set ASP.NET request execution timeout value. As per the MSDN Exception Document, default value is set to 110 seconds, in that it is remarked like:
The ExecutionTimeout property indicates the maximum number of seconds
a request is allowed to execute before being automatically shut down
by ASP.NET.
So based on error detail with event code 3001 occurs because no response was received during the time-out period for a request. You can use IIS troubleshooting failed request mechanism to figure it out exact issue like any poor performance/deadlocks when making calls from your ASP.NET application.
Secondly, it is not related to user's internet connectivity issue otherwise you get exception with status like connection-closed or keep alive failure. See this article for detail. The browser is going to wait for a 60 minutes(which is very long period of time that server isn't going to answer any request)for server to response.
And at any case when the browser abandons any request, it is going to close the socket and you'll get an error page from the browser. You don't get anything related to sever-end.

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

I am using MVC(ASP.Net + C#) based application. I have used Jquery DataTable to display records. Now issue is that for some records its working good and for some records it's giving me error like "Timeout expired" at front end side.
I am using Entity Framework & Stored Procedure to fetch records. For some values It's giving me Timeout Error. If I directly executed this Sp with those require parameters (in which it's giving me Timeout Error) then it's working fine(but taking bit time around 11 seconds in SQL Server.). I just getting Timeout error frond end side.
I am getting below error.
{"Timeout expired. The timeout period elapsed prior to completion of
the operation or the server is not responding."} {"The wait operation
timed out"}
I have tried added in web.config
Connection Lifetime=120;
Min Pool Size=120;
Connection Timeout=300;
Max Pool Size=1000;Pooling=true;
<httpRuntime executionTimeout="180" maxRequestLength="2000000000" />
But didn't workout.
My Web.Config as below.
<add name="TestEntities" connectionString="metadata=res://*/Test2.csdl|res://*/Test2.ssdl|res://*/Test2.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=Test2;integrated security=True;multipleactiveresultsets=True;Connection Lifetime=120;Min Pool Size=120;Connection Timeout=300;Max Pool Size=1000;Pooling=true;App=EntityFramework"" providerName="System.Data.EntityClient" />
Please help.
Thanks
-Nimesh
SQL server creates an execution plan for stored procedures to optimize the performance for further executions (parameter sniffing). When you execute this stored procedure on SSMS, it works fine but when you try to execute the same stored procedure from your ASP.NET MVC application, you'd face the timeout issue.
You can fix this by re-creating/altering your stored procedure WITH RECOMPILE option (after your parameters). I faced this issue today; altered my stored procedure WITH RECOMPILE option and it worked like a charm. For more details, read about Parameter Sniffing.
I have solved issue by increasing CommandTimeout To 120
Db.CommandTimeout = 120;

API Calls with long DB query returning Gateway Timeout out despite extending timeouts

I'm using Entity Framework 6 to access a SQL Server in an API application. The API server and DB server are separate. I have a known long query that takes a little more than a minute to run. I have set the CommandTimeout on my EF DbContext using the following code:
db.Database.CommandTimeout = 20 * 60; // 20 minutes
Unfortunately, this does not seem to have any affect because the query still times out in less than a minute and the server returns a 504 Gateway Timeout error.
Why does this change not have any affect on the command execution time limit?
Is there something else I should be doing to allow this query to run longer?
Some more details:
I have written a desktop app that makes API calls to an API server which in turn makes queries to the db server. On the desktop application side, I have set the HttpClient property:
httpClient = new HttpClient { Timeout = new TimeSpan( 0, 20, 0 ) };
On the API server side, I have set the execution timeout:
<system.web>
<httpRuntime requestPathInvalidCharacters="" maxRequestLength="2097151" executionTimeout="30000" />
</system.web>
And on the API server, I've set the SQL command timeout as above.
At some point, the response always ends after a little less than a minute despite the fact that I've set all the timeouts I can think of to 20 minutes. I assumed the 504 was caused by the db timeout, but I suppose it's just as likely that it's between the desktop app and the API server.
Regardless, I'm running out of ideas so anything will help.
Turns out there was another timeout setting I wasn't thinking about. Because I host the API and database servers on Amazon Web Services using Elastic Beanstalk, there was a Load Balancer between my desktop application and the API server. The default timeout is 60 seconds. Here is a link to increase the Load Balancer's timeout settings:
http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/config-idle-timeout.html

Nhibernate Connection Pool Problems

we are having some connection pool issues with Nhibernate on an MVC3 web application which is running with SQL Express and dealing with multiple concurrent AJAX based requests.
Every so often (hours in between) we see errors starting which show:
NHibernate.Util.ADOExceptionReporter
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
then a load of
While preparing select TOP (#p0)
....
an error occurred
We have to recycle the IIS app pool to stop 500 errors from being thrown after that.
Looking at the SQL Server we see:
select * from sys.dm_exec_sessions
... gives about 30 sessions with IDs above 51 (i.e. user sessions)
select * from sys.dm_exec_connections
... gives around the same amount
BUT
select ##connections
... gives results with 79022
Is this indicating that the connections are never released?
The Nhibernate sessions are for the lifetime of the request.
Does anyone have any experience of anything like this or can point us in the right direction?
Many thanks
Richard
You can't have more then 32767 connection to SQL Server.
##CONNECTIONS also gives (my bold)
Returns the number of attempted connections, either successful or unsuccessful since SQL Server was last started.
Not current connection
I suspect that your pool is not set up correctly so it's exhausted too quickly.
Or you are not releasing connections correctly and you're checking SQL Server after you recycle IIS.

ASP.NET SqlConnection Timeout issue

I have run into a frustrating issue which I originally thought was a connection leak but that does not seem to be the case. The secnario is this: the data access for this application is using the Enterprise Libraries (v4) from Microsoft. All data access calls are wrapped in using statements such as
using (DbCommand dbCommand = db.GetStoredProcCommand("sproc"))
{
db.AddInParameter(dbCommand, "MaxReturn", DbType.Int32, MaxReturn);
...more code
}
Now the index of this application makes 8 calls to the database to load everything and I can bring the application to its knees by refreshing the index about 15 times. It seems that when the the database reaches 113 connections is when I recieve this error. Here is what makes this weird:
I have run similar code with the entlib on high traffic sites and have NEVER had this problem ever.
If I kill all the connections to the database and get the production application back up and running everytime I refresh the application I can run this SQL
SELECT DB_NAME(dbid) as 'Database Name',
COUNT(dbid) as 'Total Connections'
FROM sys.sysprocesses WITH (nolock)
WHERE dbid > 0
GROUP BY dbid
I can see the number of connections actively increasing with each page refresh. Running the same code on my local box with the same connection string does not cause this problem. Further if the production website is down I can fire up the site via Visual Studio and run it fine and the only difference between the two is that the production site has Windows authentication turned on and my local copy doesn't. Turning windows authentication off seems to have no effect on the server.
I have absolutely no clue what is causing this or why the connections are not being disposed of in SQL Server. The EntLib objects do no explose .Close() methods for anything so I can't explictily close the object.
Any thoughts?
Thanks!
Edit
Wow I just noticed that I never actually posted the error message. Oy. The actual connection error is: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
Check that the stored procedure you are executing is not running into a row or table lock. Also if you can possibly try to deploy in another server and check if the application would crawl again.
Also try to increase the maximum allowed connections for your SQL server.
think the “Timeout Expired” error is a general issue and may have seveal causes. Increasing the TimeOut can solve some of them but not all.
You may also refer to the following links to troubleshoot and fix the error
http://techielion.blogspot.com/2007/01/error-timeout-expired-timeout-period.html
Could it be a configuration issue on the server?
How do you make a connection to the database on the production server?
That might be an area worth looking into.
While I don't know the answer I can suggest that for some reason connections are not being closed by you application when run in production. (Stating the obvious)
You might want examine your network configuration between the web server and sql server. High latency networks can cause connections not being closed in time.
Also it might help looking at the performance counters listed in the end of the following msdn article:
http://msdn.microsoft.com/en-us/library/8xx3tyca%28VS.71%29.aspx
Finally, if nothing else helps, I'd get debugger and Enterprise Library source code on production and debug your code inside the enterprise library to find out why connections are not being closed.
Silly question are you properly closing your DataReader? If not this could be the problem and the difference in behaviour between dev and prod can be caused by different garbage collection patterns.
I would disable connection pooling and try to suppress it (heh). Just add ";Pooling=false" to your connection string.
Or, perhaps you could add something like the following 'cleanup' code to your page (which closes any connection left open when the page unloads) - right in the 'using' clause:
System.Web.UI.Page page = HttpContext.Current.Handler as System.Web.UI.Page;
if (page != null) {
page.Unload += (EventHandler)delegate(object s, EventArgs e) {
try {
dbCommand.Connection.Close();
} catch (Exception) {
} finally {
result = null;
}
};
}
Also, make sure you've enabled the 'shared memory' protocoll if your SQL server and IIS are on the same machine (a real performance booster)!

Categories

Resources