3

関連する質問: 別のマシンでアプリケーションを実行するとエラーが発生する

これは私の App.config ファイルがどのように見えるかです:

<?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>

これを開発マシンで実行すると機能しますが、別のコンピューターにデプロイすると、データ プロバイダー エラーが発生します。(上記の関連する質問を参照してください)。

提案された解決策は、これを App.config ファイルに追加することでした。

<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>

これを App.config ファイルに追加すると、Visual Studio 2010 でアプリケーションを起動するときに次のエラーが発生します。

system.data の構成セクション ハンドラーの作成中にエラーが発生しました: 列 'InvariantName' は一意に制限されています。値 'System.Data.SQLite' は既に存在します。(C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\bin\Debug\DocumentScannerDanyly.vshost.exe.Config 行 13)

このエラーが何であるかについて何か提案はありますか? また、.sqlite ファイルの場所はそれがインストールされている場所に相対的であるため、AppConfig ファイルの connectionString をより動的なものに変更する必要がありますか?

助けてくれてありがとう。

編集:

ここで誰かが提案したようにこれを構成に追加すると、エラーが発生します。

<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>

登録された .Net Framework Data Provider の検索または読み込みに失敗しました。

4

3 に答える 3

11

これは、SqlLite をインストールすると、machine.config が次のように更新されるためです。

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

SqlLite がインストールされているマシンで実行していないため、DbProviderFactories は SqlLite を認識していません。

宛先マシンに SqlLite をインストールするか、これを構成に追加します。

<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>

これにより、machine.config との衝突がなくなり、ターゲット マシンで動作できるようになります。他の SQL データ プロバイダーを使用している場合は、それも追加する必要があります。

編集

クリアが機能しない場合は、次を試してください。

<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>
于 2010-11-19T14:30:14.633 に答える
3

上記のソリューションを追加すると、まったく同じ問題が発生しました

登録された .Net Framework Data Provider の検索または読み込みに失敗しました。

System.Data.SQLiteしかし、それを解決したのは、参照で「ローカルのコピー」をtrueに設定することでしたSystem.Data.SQLite.Linq

あなたにも役立つことを願っています。

于 2013-03-16T11:30:43.687 に答える
2

問題は、接続文字列でデスクトップへのパスをハードコーディングしている可能性が最も高いです。

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

このファイルが他のマシンのまったく同じ場所に存在しない限り、機能しない可能性があります

于 2010-11-19T14:29:31.913 に答える