• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

OleDb.... Exception handling

Hello,

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

thanks



0
brdrok
Asked:
brdrok
  • 2
  • 2
1 Solution
 
Razzie_Commented:
Well yes there is the System.Data.OleDb.OleDbException class.
0
 
brdrokAuthor Commented:
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
}
0
 
Razzie_Commented:
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
0
 
brdrokAuthor Commented:
Thanks Razzie for the very useful info.....

you rock....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now