Solved

Handling OLE DB Error messages in ASP

Posted on 2003-11-06
6
397 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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 …

735 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