Link to home
Start Free TrialLog in
Avatar of brdrok
brdrok

asked on

OleDb.... Exception handling

Hello,

is there a particular exception class that handles errors thrown by System.Data.OleDb?

thanks



ASKER CERTIFIED SOLUTION
Avatar of Razzie_
Razzie_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brdrok
brdrok

ASKER

hey Razzie,

thanks for the answer...got another question for you (increased point value to 100).  why does the code go to the "Exception" as opposed to the "System.Data.OleDb.OleDbException" catch block?

try
{
      string sqlString = "SELECT * FROM " + myRegion + " WHERE Status_FK = " + myStatus;
      System.Data.OleDb.OleDbConnection myConn = new OleDbConnection(CONNSTRING);
      System.Data.OleDb.OleDbDataAdapter myDA = new OleDbDataAdapter();  <---i create a mistake here
      System.Data.DataSet myDS = new DataSet();
      myDA.Fill(myDS, "ProgressReport");   <----Exception is thrown here and goes to the "Exception" catch block.
}
catch (System.Data.OleDb.OleDbException oleEx)
{
                MessageBox.Show(oleEx.Message);
      return;
}
catch (Exception ex)
{
      MessageBox.Show(ex.Message);
      return;
}
finally
{
      //TODO: DO CLEAN UP HERE
}
OleDbExceptions are only thrown when something goes wrong at the server, for example invalid table name, non-existend column names, etc.

The error you create (not setting the select query) is an InvalidOperationException. It doesn't have anything to do with the actual database data, or table structures.

I think that when you enter something invalid in your sql query, like an invalid table name, the OleDbException will be thrown.

HTH,

Razzie
Avatar of brdrok

ASKER

Thanks Razzie for the very useful info.....

you rock....