Solved

Handling OLE DB Error messages in ASP

Posted on 2003-11-06
6
385 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

744 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

15 Experts available now in Live!

Get 1:1 Help Now