Error Number on ORMQueryExecutionException

Posts   
 
    
helga
User
Posts: 17
Joined: 15-Jun-2007
# Posted on: 05-Oct-2007 21:16:23   

I'm using action stored procedure to update data in web, i.e. user e-mail.

The e-mail field in the db is marked as to be unique.

On attempting to update duplicate e-mail the adapter returns correctly the ORMQueryExecutionException

I want to be able to extract the error number to ensure that this is the correct error and also to be able to build a error code to error message class for user readability.

This counts for all these ORM Errors.

Your help, as a matter of urgency, will be appreciated.

Kind Regards Helga

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Oct-2007 05:44:06   
David Elizondo | LLBLGen Support Team
helga
User
Posts: 17
Joined: 15-Jun-2007
# Posted on: 06-Oct-2007 17:40:07   

Hi

Thanks for taking the time to reply but it does not supply the correct answer. In one of the threads the client asked a specific question that is the exact same question that i am asking.

What is the error number of the error. When you get a SQLException sExp you can use sExp.Number and use the number to generate a readable message to your client.

The thread answers explains a whole bunch of stuff re innerexception but from what i can make out the OMR Errors does not provide a error number or contain the error number from the sql server.

It's really not helpfull if you have to write a whole class just to determine what error was thrown by sql server cause you must remember when updating a sp in a database it might return contstraint error, dbnull value error, or whatever error you want sql server to check for and return without writting a bunch of code-behind code.

Regards Helga

Posts: 254
Joined: 16-Nov-2006
# Posted on: 06-Oct-2007 22:21:09   

Hi Helga,

After reviewing those threads I must admit it does sound confusing. Hopefully I can clear this up for you.

Firstly if your ever investigating how exceptions are propogated up through an application or third party component a useful debugging tip is to set the debugger to break on any CLR exception which occurs. You can do this through the exceptions dialog in VS.NET 2003 / 2005. When executing the application will break when any exceptions are thrown. If you ensure you have a reference to the LLBLGEN runtime library source code you willl clearly see where LLBLGEN is throwing and handling the exceptions.

However you shouldn't have to get that level of detail to get the information you want here. You should be able to write code such as

           user = new UserEntity();
            user.Name = "matthew";
            user.Email = "matt.adamson@llblgen.com";
            try
            {
                user.Save();
            }
            catch(ORMQueryExecutionException exception)
            {
                if(exception.InnerException is SqlException)
                {
                    Int32 errorCode = ((exception.InnerException) as SqlException).ErrorCode;

                    if (errorCode == -2146232060)
                    {
                        // TODO Handle error code for unique constraint here.
                    }
                }

            }

Let me know if this isn't clear