SQL Timeout after database exceptions

234 Views Asked by At

I'm using Castle ActiveRecord as my ORM in my ASP.NET webapplication. I'm using their SessionPerRequest-approach and this works fine. However, if an error occures on the database-level (f.e. a constraint error when deleting an item or a truncation error (String or binary data would be truncated.)) I keep getting timeouts with all queries I run after the error. This happends for about ten minutes, then everything runs fine again. I think this has to do with the Transaction not closing correctly. I can't seem to find a way to correctly close the transaction after an error, so I'm looking now to minimize the effects. I've tried setting the Command Timeout and Connection Timeout to a smaller number, but this does not seem to work. Does anybody got an idea how to solve this problem?

1

There are 1 best solutions below

0
Juy Juka On

as far as I can understand your Situation, there are two possible sources for your problem:

1. Data-Base-Server-Configuration You haven't tould us wich database you are using, so I can only guess. If the SQL-commands causes locks they could be waiting for the old command that caused an exception and will never resolve (aka. TimeOut). If the transaction is stored in a log file, the log file might be physically full (very unlikely) and no future commands can be stored till the old command that caused an exception is resolved (aka. TimeOut). There might be - depending uppon the data base system - hundrets of other reasons fro the error. In eiter way it is easy to test and if it is caused by the data-base, then you can just start a new request with only the SQL-commands, no NHibernate and more geared to wards data-base-experts. How to test, if it is a data-base configuration problem? Simple. You just have to cause the error and then use the administrative tool (for example MS SQL Server Management Studio, Oracle SQL Developer, etc.) to send the same SQL-command as your Software is sending. If this command from the administrative tool has the same problems as your Software, then it is a data-base configuration problem and you should be able to reproduce and solve it within the database only. If the comman from the administrative tool resolves without a timeout then the problem is within the code or configuration of your software.

2. SessionPerRequest isn't working I guess that with "happens for about 10 minutes" you mean that after not using the software for 10 minutes (round about) the problem stops. I also guess that the problem will persist for longer then 10 minutes if you keep sending new requests from your browser to the server (IIS) without longer breaks. This would mean that eiter the IIS-web-session or the IIS-application-pool (both used by your software) get a timeout and are disposed what also disposes every static variable, every session variable and every NHibernate-session that is stored in there! If you want to use a SessionPerRequest solution to avoid this problem, then you have to implement a SessionPerRequest aproach for this yourself! ! You have to have code in your application that is creation a new NHibernate-session at the beginning of a request and disposing it's own NHiberante-session at the end of the request, this isn't coded into NHibernate itself and can not be activated with any configuration, you have to code it yourself.

Greetings Juy Juka