Вопрос

I am trying to use 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();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top