PDA

View Full Version : Trapping 0x80004005 error


avivit
01-21-2004, 12:43 PM
Hi,

I am trying to trap an error, so that the user will not see it, and that the next line will be excetuted (redirection).
I created on purpose "0x80004005" error, and it is not trapped, but it is shown on whole page for all to see, and does not continue from there. Why is my traaping ignored?

I use no sub/functions. All as main data.

The error refers to trying to insert a new record to MS-ACCESS db containing an existing ID, when ID IS teh key field (thus unique, as should be).

The error:"Microsoft JET Database Engine (0x80004005)
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again."

How can I trap the error, and my is my trapping ignored?

---------------------------
CODE:
---------------------------

On error resume next
'Opening db+recordset...
'Exceuting sql statement (Insert)
'error handling:
IF objDB.errors.count>0 then
response.write "Database Errors"
else
response.write("great")
end if

If err.number>0 then
response.write "VBScript Errors"
'Closing recordset and db and setting to nothing
Response.Redirect (mySite)
--------------------------------------------
--------------------------------------------
Not trapped, I get the above default error, and the redirection does not take place.

Helpppppp

Thanks

glenngv
01-22-2004, 07:25 AM
Does the Errors collection of the Connection object contain errors?

If objDB.errors.count>0 then
response.write "Database Errors"
else
response.write "great"
end if

Which string was written to the browser?
I asked this because it might be that errors collection is empty.
This is an excerpt from devguru:

Each Error object contains a specific provider (not an ADO) error or warning. ADO errors are handled differently. When an ADO error occurs, it generates a run-time exception-handling mechanism.


I think that the error you were encountering is an ADO error. So the code should be like this:

'Opening db+recordset...

On error resume next
'Executing sql statement (Insert)

'error handling:
If err.number<>0 then
response.write "Database Errors"
else
response.write "great"
end if

avivit
01-22-2004, 11:53 AM
Thanks Glenn.

I see now my error handling code was not in the right place.
So now it works.

Actually it is one of objDB.errors
and not the err.number collection.

Now a new problem,
When getting the default error, the line in which the error ocoours in code is mentioned , but when using the error collection to trap the error , I didn't find how to get the line number too. Possible?

I see I can get follwing data:

objDB.errors(counter).number
objDB.errors(counter).description
Thanks

glenngv
01-23-2004, 03:00 AM
I think you can't get the line number. If found no line number property in the ADO reference of devguru.

But you can try this and see if you can spot a line number from the output.


For Each objError in objDB.Errors
ErrorInfo = "Description; " & objError.Description & "<br>" &_
"Help Context: " & objError.HelpContext & "<br>" &_
"Help File: " & objError.HelpFile & "<br>" &_
"Native Error: " & objError.NativeError & "<br>" &_
"Number: " & objError.Number & "<br>" &_
"Source: " & objError.Source & "<br>" &_
"SQL State: " & objError.SQLState & "<br>"

Response.Write ErrorInfo & "<br><br>"
Next

fractalvibes
01-24-2004, 04:38 AM
Use an editor like EditPlus that shows the line numbers. Helpfull beyond belief in many cases. Many times you have to take that line number and work backwords, look for that missing end if, etc.
The 8000405 basically means that ADO doesn't know what you are asking for - truly a '...Houston, we have a problem...' - type message that does not provide any specific diagnostic info...


fv

glenngv
01-26-2004, 02:10 AM
avivit is not fixing the error. He/She is trying to handle runtime errors in the page, much like try-catch block in other languages.

avivit
01-26-2004, 07:35 AM
I am trying to catch the errors, and lated go over the list of errors, and then see if should be fixed or not. Most should not be fixed, but I want to know they exist.