Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm working currently in an application with access and odbc.

 

I need to catch diferente errors that happen so i can treat them diferently. but it always returns the same exception. I want somthing like this

 

try
{
 execute query to the database
}
catch (exception file not found)
{
  rerturn -1
}
catch (exception odbc not found)
{
  rerturn -2
}
catch (exception table locked)
{
  rerturn -3
}
finally
{
  close connections
}

 

 

this is the simplified version of what want. But it returns always the same error and i cannot treat it.

 

this is when data source is not found

System.Data.ODBC.OdbcException:EROOR[iM002][...]Data source not found and no default driver specified.

 

 

this is when table is loked in design

 

System.Data.ODBC.OdbcException:Error[HY000][...]The table XXXX is already opened exclusively by another user, ....

 

 

how can is distinguish these exceptions from one another??

 

thx to all

Posted
You can do a switch on the NativeError or SQLState property of the Exception object in your catch block. To my knowledge you can't do a catch on a specific type of error for an Exception type.
Here's what I'm up to.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...