?
Solved

Handling OLE DB Error messages in ASP

Posted on 2003-11-06
6
Medium Priority
?
403 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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 Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

719 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