Solved

OleDb....   Exception handling

Posted on 2004-10-22
363 Views
Last Modified: 2008-03-17
Hello,

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

thanks



0
Question by:brdrok
    4 Comments
     
    LVL 8

    Accepted Solution

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

    Author Comment

    by:brdrok
    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
     
    LVL 8

    Expert Comment

    by:Razzie_
    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
     
    LVL 7

    Author Comment

    by:brdrok
    Thanks Razzie for the very useful info.....

    you rock....
    0

    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 (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. 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