When adding a configuration to the App.config file, an error occurs.

c# dbproviderfactories entity-framework sqlite

Question

Similar thought: My program crashes when I try to run it on another computer.

My App.config file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="DocumentsDBEntities" connectionString="metadata=res://*/Documents.csdl|res://*/Documents.ssdl|res://*/Documents.msl;provider=System.Data.SQLite;provider connection string=&quot;data source=C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\DocumentsDB.sqlite&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
  <appSettings>
    <add key="Username" value="administrador"/>
    <add key="Password" value="123456"/>
  </appSettings>
</configuration>

Running this on my development PC works, however I have a Data Provider issue when deploying to another computer. (See preceding related query)

The proposed remedy was to include the following in the App.config file:

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

When I begin the application with Visual Studio 2010, I receive the following problem after adding that to the App.config file:

An error occurred creating the configuration section handler for system.data: Column 'InvariantName' is constrained to be unique. Value 'System.Data.SQLite' is already present. (C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\bin\Debug\DocumentScannerDanyly.vshost.exe.Config line 13)

Any ideas as to what the problem could be? Do I need to modify the connectionString in the AppConfig file to something more dynamic as the location of the.sqlite file is relative to where it is installed?

I appreciate the support.

EDIT:

I see the following issue when I add this to the configuration as someone here suggested:

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

Failed to find or load the registered .Net Framework Data Provider.

1
3
5/23/2017 12:01:28 PM

Accepted Answer

You probably have a route to your desktop hard coded in your connection string, which is the issue:

C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\DocumentsDB.sql

Chances are it won't work unless this file is present in the exact same position on the other computer.

2
11/19/2010 2:29:31 PM

Popular Answer

This is due to the fact that after you install SqlLite, your machine.config is updated with:

<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>

DbProviderFactories is unaware of SqlLite since you are not executing on a computer where SqlLite has been installed.

Install SqlLite there, or add the following to your configuration:

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

By doing so, you will avoid conflict with your machine.config and enable it to operate on your target system. You would also need to include it if you were using another SQL data supplier.

EDIT

Try these if clear doesn't work:

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


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow