![](/img/trans.png)
[英]Adding app.config (Application Configuration File) in Visual Studio Professional 2017
[英]Error when adding a configuration to App.config file
相關問題: 在另一台機器上運行我的應用程序會給我一個錯誤
這是我的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="data source=C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\DocumentsDB.sqlite"" 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 line 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數據提供程序。
這是因為當您安裝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>
當我添加上述解決方案時,我遇到了同樣的問題
無法找到或加載已注冊的.Net Framework數據提供程序。
但解決這個問題的方法是在參考文獻中為System.Data.SQLite
和System.Data.SQLite.Linq
設置“Copy Local”為true。
我希望它也能幫到你。
問題很可能是您在連接字符串中硬編碼桌面路徑:
C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\DocumentsDB.sql
除非此文件與另一台機器上的完全相同的位置存在,否則它可能無法正常工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.