Getting an exception using ProviderFactory to create an SQLite join

I am trying to use ProviderFactory.CreateConnection () to get an SQLite connection. I get a System.ArgumentException with the following message:

"Keyword not supported: 'datetimeformat'.

Connection string:

@"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 creating an instance of SQLiteConnection. It does not work with ProviderFactory. Any suggestions on how I can solve this?

+3
source share
1 answer

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

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

And the following code then worked as expected, without exception:

IDbConnection conn = providerFactory.CreateConnection();
+2
source

Source: https://habr.com/ru/post/1794592/


All Articles