what may cause a c# application to stop after 12 hours - c#

I am developing a c# utility that updates a datatable in a database. My application stops after 12 hours showing a messagebox indicating windows error.
I am sure that there is no memory leak. Moreover, it was also stopping around 12 hours of running indicating timeout expired message. So i set the Commandtimeout property to infinity. Now this error is no more showing.
what else could be stopping the utility after 12 hours? and what does this "Windows error" message mean?
I used AppDomain.CurrentDomain.UnhandledException to handle unhandled exceptions, and i got the following message box after running the utility for long time.
Messagebox: "Timeout Expired.The timeout period elapsed prior to completion of the operation or the server is not responding"
knowing that i am using SQLServer2008 R2 and i already set all the commandTimeout to 0.
whats wrong? why i am still getting this error ?!

Why does you want your utility to work continuesly, if some thing is to carry on at regular interval then you should use the schedular for invoking your utility. This will make sure that your application is not keeping the resource in locked state.
Now coming to your point of view... if application is must to run more than 12 hrs conti. then check,.. is there any thing that makes all the connection to break forcefully example backup scheduled for the database. this will make all the connection to break even if timeout is set to infinity.

Which database are you using? I know that in mysql there is a limit from the database about how much time the connection is kept open. Maybe in your database it is 12 hours,however if this is mySql it is a bit of a problem to change the timeout setting. So remember to change both the global and local setting or else it won't change, good luck.

Some networks have a hickup every 12 hours to crash p2p applications. Maybe there is some network related problem triggered every X hours.
Is you're code correctly going to reconnect on a failure and log decent error messages or is it just going to crash?

Related

TCP Provider, error: 0 - The specified network name is no longer available

Recently we face the above issue from on of our web service log. This happens only on and off but we puzzled what may cause this error to happen. The sql is just a normal sql. First we thought this may because the long running queries but as per goggling found out that .Net 2008 will have timeout expired exception if exceed defaults 30 seconds timeout.So suspect not because the sql itself. Form the event viewer we can find NLB convergence event happen during the time. Is that NLB convergence will cause network glitch and thus cause the error triggered?

Change CommandTimeout Default Value globally

We migrated some piece of old software to a new server. We used SQL Server 2008 Enterprise in the past and now we are using SQL Server 2014 Enterprise on a new machine, so it should be faster now.
The old software is legacy software and about to expire, therefore I don't want to put much effort in fixing it. But for some reason there is a C# function running a SQL query against the database for which I get the error message
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
All I read about that is, that I have to extend the timeout time by using CommandTimeout. But unfortunately everything runs under "context connection = true". Therefore, it would take quite a bit work to rebuild this function with an opportunity to change the timeout.
And I'm asking myself, why did this run on the old machine and way it won't on the new one. So it has to do something about the new machine or the new SQL Server engine. Is there any way to change the standard timeout of 30 seconds for a command in the .NET Framework or in the SQL Server?
Thanks a lot for any suggestions!
You can set the timeout of a command with the CommandTimeout property:
var cmd = new SqlCommand { CommandTimeout = 60 }
Ok, I didn't find a sollution for the problem, yet, but the timeout is not really the source of the problem. I gained access to the old system and run some tests and it turned out that the same function on the old machine with the old server software runs a lot faster, such that there is no timeout.
Hence, I have to focus on server speed and database tuning.
Thanks to everyone who occupied himself with this question!
Edit:
I found a solution to my problem, indirectly. I couldn't find out, why the execution of the statement on the new machine takes so long. But it turned out that the statement itselft uses table variables. I changed them to a local temporary table in the database tempdb. Now the execution takes less than one second instead of more than 7 minutes!
For me, it looks like a problem with some cache or a miss-configured SQL server. Unfortunately, I'm not really the server administrator and I will not twiddle with it. But I will mention it to the administrators. At least, the program runs now perfectly.

ADO.NET How to keep my connection Active

I have created a windows service using c#.NET, The service will updated oracle tables whenever it receives new files. I have kept timer control and the time limit as 30 seconds. I am using ODP.NET as data access layer.
The very first time I will get error, but subsequently the service will work fine. If service is Idle for a long time if it receives a file, I will get "connection lost error", but after if we receives file it will loaded successfully.
Kindly suggest me do I need add any properties in connection string to fix this error?
Hello Karthik Two issues here it seems.
You are best to open and close a new connection each time your service is called.
Windows services quickly go to a latent state if not called and they will respond slower on the next call. If the caller does not have a sufficient timeout value to accomodate this lag then it will return a time out error. If you address these two points you should be fine.

Stored procedure returns "Timeout expired"

In my Windows application, I use SQL Server 2008. My database size is 5086080 KB. Now I get the error as timeout expired when saving a transaction by using a stored procedure. So I set command timeout to 1200. It works fine. But I think it shouldn't because insert data have 2 or 3 lines. Is there any other way to solve this problem?
This is detail error message:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding .
Timeout is entirely on how long the actual SQL command is likely to take.
For example example, most of our commands run sproc's that should take no longer than 30 seconds to complete, however there are a couple that run for much longer, which means they have their own high valued timeouts.
You'll need to profile how long on average your routine takes then adjust the timeout accordingly, and remember to leave room for variables like latency etc
you need to profile your sql query and your code at every step. only then will you be able to know the exact bottleneck in your program.
Is somebody else keeping a transaction open that is holding up your query? Run sp_who or sp_who2 on the server to see what else is running.

What are some good ways to debug timeouts? (C#)

I'm building a site that runs fine for a few hours, but then *.asmx and *.ashx calls start timing out.
The exception 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."
I'm using SubSonic as the ORM.
I suspect that the problem is based on a scheduled task that runs every few minutes and hits the database. When I look in SQL Server 2000's "Current Activity", I see there are:
100 processes with the status "sleeping"
100 locks
The 100 processes are from the Application ".Net SqlClient Data Provider" and the command is "AWAITING COMMAND".
So I'm guessing that's the issue . . but how do I troubleshoot it? Does this sound like a deadlock condition in the db? As soon as I
c:\> iisrestart
, everything's fine (for a while).
Thanks - I've just never encountered something like this and am not sure the best way to proceed.
Michael
It could be a duplicate of this problem - Is connection pooling working correctly in Subsonic?
If you're loading objects with Load() instead of LoadAndCloseReader(), each connection will be left open and eventually you'll exhaust the connection pool.
When you call Load() on a collection it will leave the Reader open - make sure you call LoadAndCloseReader() if you want the reader to close off - or use a using block.
It helps to have some source code as well.
I don't know anything about Subsonic, but maybe you are leaking database 'contexts'? I'd check that any database resource is being disposed after you're finished with it...

Categories

Resources