3 c# sqlite entity-framework dbproviderfactories
相关问题: 在另一台机器上运行我的应用程序会给我一个错误
这是我的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>
Run Code Online (Sandbox Code Playgroud)
在我的开发机器上运行它,但是当部署到另一台计算机时,我收到了数据提供程序错误.(见上面的相关问题).
建议的解决方案是将其添加到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>
Run Code Online (Sandbox Code Playgroud)
当我将其添加到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>
Run Code Online (Sandbox Code Playgroud)
无法找到或加载已注册的.Net Framework数据提供程序.
Bro*_*ski 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"/>
Run Code Online (Sandbox Code Playgroud)
因为您没有在安装了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>
Run Code Online (Sandbox Code Playgroud)
这将阻止您与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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12705 次 |
最近记录: |