SQL Server 2005 Timeout, Connection Was Reset - asp.net

I am loading 100,000 plus pieces of data, which should take like 30 to 40 minutes to analyze and complete. We use SQL Server 2005. Currently after a specified time (trying to get the minutes it uses), the SQL Server says the connection was reset.
Is there some setting where this can be changed so my queries can run for an hour?

SqlCommand.CommandTimeout property will let you set it in code, however unless you've got clever you could get a webserver timeout as well.
Connection reset could even be your network boys, killing it for no activity.
I'd be looking at reorgansiing this somehow. Like a request to do the work and kick off athread to do it. A status page to see where it's at. When finished provides a link to the result, or somesuch.

May be your problem is related to Worker Process(w3wp.exe). In web application After some time the worker process will be recycle. So please check this setting of "IIS". you can also reset the the timeout of "Connection Timeout" in web.config or change "CommandTimeout" in code.

Related

Asp.net and Mssql Database operations time out and rollback

I am developing an application that has a big database and it waits a bit long for the result from a few queries. Sometimes, users refreshes interface before the execution is finished. There are ten users and this scenario occurs so many times.I think scripts do not stop running on sql when the web page is refreshed (becuase performance decrasing so much after a few hours). If so, Can I stop the execution of the script when the page is refreshed. In web.config, will changing Connect Timeout attibute stop the execution and rollback operations on database after timeout period is passed? Or Is there any other option in web.config file?
No connection timeout property is meant to set the timeout after which the attempt to connect to the SQL server fails. What you need is a command timeout for your stored procedure. If you share your code, expect more help.

How to control ASP.NET request timeouts here in 2013?

We have some specific web pages and Web Api services which call long-running back end processes; and we'd like to carefully control when they should timeout.
I have created a simple MVC 4 site (in VS2012) with a page that sleeps for 200 seconds before returning. Then I set these timeouts:
(in web.config) : httpRuntime executionTimeout="120"
(in global.asax Application_Start) : Server.ScriptTimeout = 120
In IIS (7.5) Manager, I went to the site > Advanced Settings > Connection Limits, and set Connection Time-out to 120
I am not able to get this page to timeout. It successfully returns after 200 seconds without timing out at 120 seconds. I even tried using curl (disabling tcp keepalive) to take the browser out of the picture: curl --no-keepalive mysiteurl
First starting with what you already tried:
executionTimeOut=120 means when some operation is running on server and its takes more than 120 seconds to complete then that operation would time out, similar is the case for Server.ScriptTimeout. Connection Time Out specifies the time in which if a connection is not established the connection error would be returned.
That means the above error (execution time out) wouldn't happen unless a synchronous process takes over 2 minutes, or a ServerSide script runs for over 2 minutes, or the connection is not established.
What you can use.
I believe you should only be concerned with the session time out if you want the pages to time out in specified time. The other timeouts that you mentioned would work as expected, you can rely on them (refer this link if you want to test if the things are working or not).
If you are performing some db operations then you should consider altering you connection time out for db connection.
If debug mode is enabled, then these timeouts do not apply:
This time-out applies only if the debug attribute in the compilation element is False. Therefore, if the debug attribute is True, you do not have to set this attribute to a large value in order to avoid application shutdown while you are debugging (source)

SQL Server timeout caused by w3wp.exe crashing

I have a ongoing issue with my website, where it appears the W3wp.exe crashes and in turn anyone attempting to connect to the site will receive a SQL server timeout error.
The error is this...
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
What actually happens is when this occurs, the CPU usage on the server maxes out to 100% and stays there. During this time if I try and connect to the homepage the site will appear to be loading and then timeout. This is also the case when i try and connect to the database through management studio.
I get the above SQL timeout error from ELMAH when it emails me exceptions. When I do a iisreset I can once again connect to SQL server and the CPU usage drops immediately.
Now I have already posted a few questions oh here about the issue in regards to the SQL time out exception. So ill list what I have done and what im using...
• Im using Linq to SQL.
• SQLCacheDependancy.
• IIS 7.5 & SQL Server 2008 R2.
• Disposing of all objects.
• The call to the Linq to SQL dataContext is always wrapped in a USING Keyword.
These timeout errors occur infrequently, maybe once every 2 days, but today when I got up, my inbox was full of time out exceptions indicating one occurred overnight.
The other odd thing is that when for example it happened last night, it was around 4am, when I tried it this morning at 8am the site worked fine, so I appears that overtime the W3wp.exe, SQL server or both manage to either recycle or reset themselves.
Can anyone see what maybe causing this behaviour ? or point me in the right direction of what maybe the cause ? or perhaps even a possible solution ?
Any help is most appreciated
Truegilly
I would guess the timeout is because of the high CPU spike, not the other way round. If your IIS and SQL are on the same machine, try to find out the process (from task manager) which is hogging the processor.
If it is the web server, setup perform counters, especially the ones related to .NET Garbage collection, and see how frequently it is getting executed. Also check the Gen2 object size. You would have to collect this data starting from when it is running fine till CPU maxes out, and compare what is "growing" in the counters. Check if you have object tracking enabled in the data context, and also how long your using(datacontext){ ... } are.
If it is the sqlserver that is holding the CPU, then try to use the following Microsoft article to analyze the issue.

Does the Server ASP.Net timeout setting affect the client timeout setting?

I'm working with ASP.Net web services and am having a problem with a long-running process that takes about 5 minutes to complete, and it's timing out. To fix this, I was able to set the executionTimeout on the server's web.config to 10 minutes, and then set the .Timeout property on the Web Service object to approximately 9 minutes. Now, I'm worried that this may possibly cause some other web service calls to sit there for 10 minutes before they time out rather than the previous 90-100 seconds. I know the default on the client side is 100 seconds, but wasn't sure if updating the server's timeout setting would affect this.
Bottom line is - Is it safe to update the server's timeout setting to a long amount like 10 minutes, and rely on the default timeout on the client, or could this end up causing some problems?
Thanks!
The web is not supposed to work like this. If you have a long running process, you should call it in a new thread and post the answer after the page has finish loading on the client side (either with a callback or by querying the server-side every x minutes to check if the process has finished). This way you avoid timeouts and the user gets their page (even incomplete) in a user-friendly time. This is important because if the user does not get their page in a reasonable time, they will be unhappy and try to reload the page (and maybe restart your process...).

browser timeouts while asp.net application keeps running

I'm encountering a situation where it takes a long time for ASP.NET to generate reply with the web page (more than 2 hours). It due to the codebehind running for a while (very long, slow loop).
Browser (both IE & Firefox) stops waiting for the reply (after about an hour) and gives generic cannot display webpage error (similar to what you would see if you'd try to navige to non-existing server).
At the same time asp.net app keeps going (I can see it in debugger) and eventually completes.
Why does this happen? Are there any settings in web.config to influence this? I'm hoping there's a timeout setting that I'm missing that's causing this.
Maybe a settings in IE or Firefox? But I think they wait while the server is keeping connection alive.
I'm experiencing this even when I launch app in debug mode (with compilation debug="true") on my local machine from VS (so it's not running on IIS, but on ASP.NET Dev Server).
I know it's bad that it takes so long to generate the page, but it doesn't matter at this stage. Speeding it up would take a lot of extra work and the delay doesn't really matter. This is used internally.
I realize I can redesign around this issue running logic to a background process and getting notified when it's done through AJAX, or pull it to a desktop app or service or whatever. Something along those lines will be done eventually, but that's not what I'm asking about right now.
Sounds like you're using IE and it is timing out while waiting for a response from the server.
You can find a technet article to adjust this limit:
http://support.microsoft.com/kb/181050
CAUSE
By design, Internet Explorer imposes a
time-out limit for the server to
return data. The time-out limit is
five minutes for versions 4.0 and 4.01
and is 60 minutes for versions 5.x, 6,
and 7. As a result, Internet Explorer
does not wait endlessly for the server
to come back with data when the server
has a problem. Back to the top
RESOLUTION
In general, if a page does not return within a few
minutes, many users perceive that a
problem has occurred and stop the
process. Therefore, design your server
processes to return data within 5
minutes so that users do not have to
wait for an extensive period of time.
The entire paradigm of the Web is of request/response. Not request, wait two hours, response!
If the work takes so long to do, then have the page request trigger the work, and then not wait for it. Put the long-running code into a Windows service, and have the service listen to an MSMQ queue (or use WCF with an MSMQ endpoint). Have the page send requests for work to this queue. The service will read a request, maybe start up a new thread to process it, then write a response to another queue, file, or whatever.
The same page, or a different, "progress" page can poll the response queue or file for responses, and update the user, assuming the user still cares after two hours.
For something that takes this long, I would figure out a way to kick it off via AJAX and then periodically check on it's status. The background process should update some status variable on a regular basis and store it's data in the cache or session when complete. When it completes and the browser detects this (via AJAX), have the browser do a real postback (or get by changing location.href), pick up the saved data, and generate the page.
I have a process that can take a few minutes so I spin off a separate thread and send the result via ftp. If an error occures in the process I send myself an error message including the stack trace. You may want to consider sending the results via email or some other place then the browser and use a thread as well.

Resources