c# - Format of the initialization string does not conform to the OLE DB specification -


i'm getting following error when trying read excel file using third-party component

format of initialization string not conform ole db specification

now, know words "third party component" going set off alarm bells here, hear me out.

here's connection string i'm using

provider=microsoft.ace.oledb.12.0; data source=c:\users\rory\downloads\testdb_4.xls; extended properties='excel 8.0;hdr=yes;'; 

i've got exact connection string work no problem following c# code

using (oledbconnection conn = new oledbconnection()) {     datatable dt = new datatable();     conn.connectionstring = connstring;     using (oledbcommand comm = new oledbcommand())     {         comm.commandtext = "select * [test_db$]";          // test_db name of sheet         comm.connection = conn;         using (oledbdataadapter da = new oledbdataadapter())         {             da.selectcommand = comm;             da.fill(dt);             // stuff dt         }     } } 

this works expected, , datatable filled data excel file. when try access component, error above.

i'm not expert on ole db, under impression drivers @ os level , if work 1 app / connection string should work apps same connection string. wrong? , if so, have clue what's going on here?

i have contacted support component.

the solution ended being replace single quotes escaped doubles.

 string conn = "provider=microsoft.ace.oledb.12.0;" +   "data source=c:\users\rory\downloads\testdb_4.xls;" +   "extended properties='excel 8.0;hdr=yes;'"; // single quotes 

became

 string conn = "provider=microsoft.ace.oledb.12.0;" +   "data source=c:\users\rory\downloads\testdb_4.xls;" +   "extended properties=\"excel 8.0;hdr=yes;\""; // escaped double quotes 

oledbconnection had no problem single quotes apparently apps , components do.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -