Thread: OLEDB Connection String to Excel

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    24

    OLEDB Connection String to Excel

    Hi there

    Im trying to connect to the DB using oleDb . I am tryign to connect to an Excel DB

    Based on all sources I could find on the net, the connection string has to be

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""

    explanation:
    "HDR=Yes;" indicates that the first row contains columnnames, not data
    "IMEX=1;" tells the driver to always read "intermixed" data columns as text
    Text


    So, in my program, Im writing ===>

    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\xl.xls;Extended Properties=\"Excel 8.0\";\"HDR=Yes;IMEX=1\"\"");

    I keep getting an exception saying that "Format of the initialization string does not conform to the OLE DB specification. Starting around char[102] in the connection string


    What am I doing wrong?
    And if you get no joy from music hall
    Remember there is always alcohol
    And If you get no joy from Gin
    Here is the abyss jump in

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Why do you have 2 double quotes at the end of your string ? Try a single double quote...
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    24
    no. it doesn't do the trick....Still getting an exception
    And if you get no joy from music hall
    Remember there is always alcohol
    And If you get no joy from Gin
    Here is the abyss jump in

  4. #4
    id id
    Guest
    There are no double quotes required between Excel 8.0 and HDR=Yes (your first one is correct!).
    Remove bold bits:

    ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\xl.xls;Extended Properties=\"Excel 8.0\";\"HDR=Yes;IMEX=1\"");

    Don't kick yourself as I had to go through char by char between your one and a working one I use to find the error.

  5. #5
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    Code:
    OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\xl.xls;Extended Properties= Excel 8.0;"HDR=Yes;IMEX=1);
    use the @ sigh before a string if u would like to ignore things like // /" etc ..instead you can just put them the way they should be typed in ....
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM