UNIQUE constraint exception handling

Posts   
 
    
mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 05-May-2009 15:44:25   

Salam,

I have a table that contain UNIQUE constraint

in my application, I want to handle exception that thrown by UNIQUE constraint

how i catch it ???

I know that in-clouded in ORMQueryExecutionException class, But i think it contains many exceptions other than UNIQUE constraint exception

How to identify UNIQUE constraint exception ??


            try
            {
                DataAccess.DataBase.Insert(brokerDataEn);
            }
            catch(ORMQueryExecutionException ex)
            {
                
            }

I use LLBL version 2.6 Adapter mode SQl 2008

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 05-May-2009 17:08:39   

You can query the exception message to see if it contains the text related to the exact error you wish to catch.

pseudo-code...



if (ex.Message.Contains("violation of unique constraint")
{
    //process exception
}


Matt

mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 05-May-2009 17:40:38   

thanks Matt...

Now I'm be sure there is no way to identify unique constraint except quering the exception message frowning