Solved

Handling OLE DB Error messages in ASP

Posted on 2003-11-06
6
394 Views
Last Modified: 2008-02-01
I have been asked to put a delete key on certain database fields in an application and know that the ASP will fall over if the user tries to delete a record which is linked to another record in another table which is referentially linked - I have forced this in the relationship.

I do not want all associated records deleted but I do wnat to capture the error message and present it in a more user friendly way.

How do I capture the following screen info so that I can re-present it in a nice neat table.....


Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] The record cannot be deleted or changed because table 'Product' includes related records.

/stone/product_select_maintenance.asp, line 218

 
0
Comment
Question by:Laride
6 Comments
 
LVL 1

Expert Comment

by:KeyPakt
ID: 9694113
I do not know the code in ASP but in C++ Builder I handle this as follows.

//Declarations
#include <ComObj.hpp>

//Code
try
{
    /*Delete record from table code*/
}
catch (EOleException &e)
{
    if (e.ErrorCode == 80004005)
    {
        ShowMessage("You are trying to remove a record that are linked with records in another table....");
        /*Error has been captured so you can do what you like here!*/
    }
}

Hope this code can give you a hint on how to handle the error.
0
 

Author Comment

by:Laride
ID: 9694299
Thanks for the thought. It looks very like javascript .... could a chunk of javascript in the header grab the message and put a pop up box on the screen (or re-direct to another page) and stop the message displaying as normal ?

0
 
LVL 1

Expert Comment

by:KeyPakt
ID: 9694573
Since the catch (EOleException &e) prevents the compiler from throwing the default message you are the one handeling what to be done. If I would not have entered the ShowMessage dialog I would have gotten the error but not know about it since I redirected the error to my error handler.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:Laride
ID: 9695397
Thanks for your help KeyPakt but this has not provided me with the solution. I have re-consulted my books and have resolved the problem very simply by using the VBScript object:

On Error resume next
                    MyConn.Execute="DELETE * FROM colour_group WHERE colour_group_ID="&request("colour_group_ID")&" "
                    If err.Number<>0 then
                        response.redirect"product_select_maintenance.asp?update_routine_accessed=yes&error=colour&description="&colour_group&" "   
                        err.clear
                    End If

As the only error which is likely to occur in my situation is the failure to delete the item selected (it is only this bit of SQL code which I am trapping) then if it fails I get an error which allows me to report the failure of the system to delete and the reason why.

Sorry, no points. Question withdrawn.
0
 
LVL 32

Expert Comment

by:jadedata
ID: 10022771
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jadedata
EE Cleanup Volunteer
0
 

Accepted Solution

by:
SpazMODic earned 0 total points
ID: 10060142
PAQed, with points refunded (250)

SpazMODic
EE Moderator
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now