![](/img/trans.png)
[英]Installing and Using System.Data.SQLite (An ADO.NET provider)
[英]System.Data.SQLite ADO.NET Provider cannot be loaded on non development machine
我正在嘗試將應用程序從使用MS-SQL Server的EF3.5移植到使用SQLite的EF6。 目前,該應用程序可以在我的開發計算機上正常運行,但是一旦我嘗試將其部署到其他地方(在本例中為Installation-Test-VM),它就不會加載。 取而代之的是,我得到一個異常,指出不能使用具有不變名稱“ System.Data.SQLite”和框架提供程序類型“ System.Data.SQLite.EF6.SQLiteProviderServices,System.Data.SQLite.EF6”的ADO.NET提供程序。已加載。
我在德語中遇到了例外,原文是
Der in der Anwendungskonfigurationsdatei für den ADO.NET-Anbieter mit dem invarianten Namen 'System.Data.SQLite' registrierte Entity Framework-Anbietertyp 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' konnte nicht geladen werden.
當我從輸出目錄中刪除SQLite DLL(System.Data.SQLite.dll和System.Data.SQLite.EF6.dll)時,在開發機上也會收到相同的消息。
我的配置文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework.MappingAPI" publicKeyToken="7ee2e825d201459e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.9" newVersion="6.0.0.9" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)"
invariant="System.Data.SQLite.EF6"
description=".NET Framework Data Provider for SQLite (Entity Framework 6)"
type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<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>
</configuration>
連接是在運行時建立的,如下所示:
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "System.Data.SQLite"; //I also tried System.Data.SQLite.EF6, same result
entityBuilder.ProviderConnectionString = new SqlConnectionStringBuilder()
{
DataSource = "sqlite_master.db" //The idea is that the user will later be able to choose which DB to open via a file chooser
}.ConnectionString;
entityBuilder.Metadata = @"res://*/OTDModel.csdl|res://*/OTDModel.ssdl|res://*/OTDModel.msl";
connection = new EntityConnection(entityBuilder.ToString()); //here the exception is thrown
connection.Open();
classThatExtendsDbContext dbContext = new classThatExtendsDbContext(connection);
這兩個DLL在Visual Studio中都設置了Local Copy = True和Specific Version = False。
我還嘗試從sqlite-netFx451-binary-bundle-Win32-2013-1.0.99.0包中在VM上使用32位DLL(VM運行32位Win7,開發機運行64位)。 結果相同。
有誰知道這種行為的可能原因以及如何解決此問題?
更新
我除掉了一個舊的開發機器,該機器從未與SQLite一起使用過,並且恰好可以運行Windows 7 64Bit。 該應用程序啟動沒有任何問題。 現在,我正在設置64位VM,以查看我的問題是否僅限於32位計算機。
更新2
使用64位VM也無法正常工作。 與平常一樣的錯誤。
我現在設法解決了這個問題。
解決方案是從https://support.microsoft.com/kb/2019667手動安裝正確的Microsoft Visual C ++運行時庫
這對32位和64位VM都有幫助。 我使用的是2013-x86版本,但我猜如果編譯64位應用程序,則必須使用x64版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.