开发者

Getting exception using ProviderFactory to create a SQLite connection

I am trying to us开发者_JAVA技巧e the ProviderFactory.CreateConnection() to obtain a SQLite connection. I am getting a System.ArgumentException with the following message:

"Keyword not supported: 'datetimeformat'."

The connection string is:

@"data source=d:\db\Test.db3;Pooling=True;Max Pool Size=10;datetimeformat=Ticks"

In the app.config file I have:

<system.data>
  <DbProviderFactories>
    <remove invariant="System.Data.SQLite"/>
    <add name="SQLite Data Provider" invariant="System.Data.SQLite"
       support="3F" description=".Net Framework Data Provider for SQLite"
         type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
  </DbProviderFactories>
</system.data>

The connection string works when I instantiate a SQLiteConnection instance. It fails using the ProviderFactory. Any suggestions on how I can resolve this?


It turned out, that I forgot to execute the following line of code:

DbProviderFactory providerFactory =
    DbProviderFactories.GetFactory("System.Data.SqlClient");

And the ensuing code worked then as expected without exception:

IDbConnection conn = providerFactory.CreateConnection();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜