wtorek, 30 października 2012

Retreive sqlexception from exception

SqlExceptionerror code: http://www.sql-server-helper.com/error-messages/msg-1-500.aspx

try
{

}
catch( Exception ex )
{

   SqlException sqlex = ex as SqlException;  // no error if can't cast =>  sets null

   if( sqlex != null )
   {
       
          switch ( sqlex.Number )
          {
                case 208:
                              [...]
                              break;
                 default:
                              [...]
                              break; 
          }

    }
    else // other exception type
    {
         [...]
     }

}//catch

Brak komentarzy:

Prześlij komentarz