views:

916

answers:

3

In classic asp page, i need to catch the error description and insert into a table in the database. when i use 'on error resume next', i am getting a timeout error as follows:

The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools

Please help me to catch the exception and insert into database.

A: 

Why not investigate/fix the timeout issue rather than try and catch the exception? Whilst you should log errors you should also investigate why it is occuring in the first place.

RichardOD
the fix doesnt work.. Any alternative..
@Cybernot- I misread your question. Initially I thought you were having ADO timeout issues. My answer of fixing the cause of the timeout still stand though.As an interim measure you can increase the timeout as documented here- http://msdn.microsoft.com/en-us/library/ms524831.aspx
RichardOD
A: 

If the exception is with anything to do with your database you might have found your answer... have you checked to see what the problem is first?

AnonJr
+6  A: 

I believe your question is "How do I trap the Script Timeout error and record it in the database". Then the answer is you can't do it with On error resume next.

The problem is that ASP has determined your script has run for too long. In order for your code to trap and record the error your code needs to continue but that is exactly what ASP has determined shouldn't happen since its time is up.

Also in general unless you can continue to do something sensible (and that does not include logging) in your script there is no point trying to use On Error Resume Next to trap the error.

Instead create a new ASP script that should run whenever you get a script error (this will include a Script timeout error). In IIS manager open your applications property dialog and select the Custom Errors tab. Edit the handler for the 500;100 HTTP error and change it to URL and the path of this ASP script.

Now you can place your error logging code in this ASP script. You can access the error thrown by the failing ASP page by accessing the Server.GetLastError method. You can also configure this page to send something friendly to the user.

AnthonyWJones
The logic is fine. if could you explain with example. it could be more helpful
For an example of using GetLastError see http://msdn.microsoft.com/en-gb/library/ms524942.aspx
AnthonyWJones