OleDb....   Exception handling

Posted on 2004-10-22
Last Modified: 2008-03-17

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


Question by:brdrok
    LVL 8

    Accepted Solution

    Well yes there is the System.Data.OleDb.OleDbException class.
    LVL 7

    Author Comment

    hey Razzie,

    thanks for the 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?

          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)
    catch (Exception ex)
          //TODO: DO CLEAN UP HERE
    LVL 8

    Expert Comment

    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.


    LVL 7

    Author Comment

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

    you rock....

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now