We have run into an unexpected exception thrown when opening a OleDbConnection
created from the return value of the OleDbConnectionStringBuilder.ConnectionString
property. Were using the OleDbConnectionStringBuilder
to update any relative DataSource
paths to absolute paths.
We get an System.Data.OleDb.OleDbException
exception when we call OleDbConnection.Open
and the message states:
"Format of the initialization string does not conform to the OLE DB specification.".
The code is:
var oleDBbuilder = new OleDbConnectionStringBuilder(connectString);
oleDBbuilder.DataSource = ResolveDataSourcePath(oleDBbuilder.DataSource);
m_pOleDb = new OleDbConnection(oleDBbuilder.ConnectionString);
m_pOleDb.Open(); // <-- Throws exception here
We have had no issue with this until we attempted to process a connect string which contained the value Mode=ReadWrite|Share Deny None;
. The value returned by OleDbConnectionStringBuilder.ConnectionString
property returns the property with the its value quoted. e.g:
This connection string (variable 'connectString'):
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\SomePath\@Some Database.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False
becomes (OleDbConnectionStringBuilder.ConnectionString):
Provider=Microsoft.Jet.OLEDB.4.0;Data Source="c:\SomePath\Some Database.mdb";Persist Security Info=False;Mode="ReadWrite|Share Deny None"
The Mode
value without quotes works without error!
I have a couple of questions:
- Is this by design? Why does it return an incompatible value?
- How can I work around this without duplicating the job of
OleDbConnectionStringBuilder
?