anorglet
asked on
asp vbscript error handling
Hello Experts,
I am trying to capture a common error in an asp page written in vbscript. The page allows users to delete a record in a database. There is a foreign key constraint that keeps users from deleting values that are used in the contraint. Attempting to delete a record gives this error message:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_age_resource_age'. The conflict occurred in database 'bmrc', table 'age_resource', column 'age_id'.
/bmrc/admin/catalog/age_de tail.asp, line 76
So...
I added the following code to capture the Err.number value
on error resume next
MM_editCmd.Execute
'trap errors on delete
IF err.number <> 0 THEN
response.Clear()
Response.Write(Err.number & "<br>")
Response.Write(err.source)
response.Write(err.descrip tion)
response.End()
END IF
This results in the following error page
-2147217900
Microsoft OLE DB Provider for ODBC Drivers[Microsoft][ODBC SQL Server Driver][SQL Server]DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_age_resource_age'. The conflict occurred in database 'bmrc', table 'age_resource', column 'age_id'.
So...
I then edited my code to catch this specific error and tell users to delete the related records
IF err.number <> 0 THEN
'trap cannot cascade delete
IF err.number = "-21477217900" THEN
Response.Clear()
Response.Write("The age you are trying to delete is still in use. <br> Please remove all related records")
Response.End()
ELSE
response.Clear()
Response.Write(Err.number & "<br>")
Response.Write(err.source)
response.Write(err.descrip tion)
response.End()
END IF
END IF
The if err.number = "-21blah" never fires the else always fires. I also tried if err.number = -21blah without the quotes and the same thing occurs. What am I doing wrong ??
Thanks,
anorglet
I am trying to capture a common error in an asp page written in vbscript. The page allows users to delete a record in a database. There is a foreign key constraint that keeps users from deleting values that are used in the contraint. Attempting to delete a record gives this error message:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_age_resource_age'. The conflict occurred in database 'bmrc', table 'age_resource', column 'age_id'.
/bmrc/admin/catalog/age_de
So...
I added the following code to capture the Err.number value
on error resume next
MM_editCmd.Execute
'trap errors on delete
IF err.number <> 0 THEN
response.Clear()
Response.Write(Err.number & "<br>")
Response.Write(err.source)
response.Write(err.descrip
response.End()
END IF
This results in the following error page
-2147217900
Microsoft OLE DB Provider for ODBC Drivers[Microsoft][ODBC SQL Server Driver][SQL Server]DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_age_resource_age'. The conflict occurred in database 'bmrc', table 'age_resource', column 'age_id'.
So...
I then edited my code to catch this specific error and tell users to delete the related records
IF err.number <> 0 THEN
'trap cannot cascade delete
IF err.number = "-21477217900" THEN
Response.Clear()
Response.Write("The age you are trying to delete is still in use. <br> Please remove all related records")
Response.End()
ELSE
response.Clear()
Response.Write(Err.number & "<br>")
Response.Write(err.source)
response.Write(err.descrip
response.End()
END IF
END IF
The if err.number = "-21blah" never fires the else always fires. I also tried if err.number = -21blah without the quotes and the same thing occurs. What am I doing wrong ??
Thanks,
anorglet
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks erici!
anorglet