Solved

Handling OLE DB Error messages in ASP

Posted on 2003-11-06
6
401 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 

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

Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

632 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