我正在開發一個使用實體框架4和SQL Server CE數據庫3.5的WPF應用程序,它正常工作。無需安裝驅動程序的SQL Server CE上的實體框架
但是我想讓這個應用程序在安裝了.Net Framework 4但沒有驅動程序SQL Server Compact 3.5
的機器上運行。並沒有安裝程序。可能嗎?
我曾嘗試以下:
在App.config創建節
<configuration> <connectionStrings> <add name="DbEntities" connectionString="metadata=res://*/Model.Model1.csdl|res://*/Model.Model1.ssdl|res://*/Model.Model1.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=|DataDirectory|\Data\Database1.sdf"" providerName="System.Data.EntityClient"/> </connectionStrings> <system.data> <DbProviderFactories> <add name="SQL Server Compact Edition Data Provider" invariant="System.Data.SqlServerCe" description=".NET Framework Data Provider for Microsoft SQL Server Compact Edition" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/> </DbProviderFactories> </system.data> </configuration>
引用添加
System.Data.SqlServerCe
和System.Data.SqlServerCe.Entity
並允許本地副本建設應用程序並將其複製到未安裝SQL Server CE驅動程序的計算機上。當談到創建數據方面,我不斷收到此錯誤:
System.ArgumentException:指定的存儲提供不能在配置中找到,或者是無效的。 --->
System.ArgumentException:無法找到請求的.Net Framework數據提供程序。它可能沒有安裝。
我是否失去時間?或者我應該切換到SQLite?
謝謝!
編輯:
由於josemiguel.torres的回答,我在this post檢查detailling如何實現這一目標。但是,我仍然有彙編錯誤。
"System.IO.FileLoadException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)"
所以我不得不看看this other post解釋如何解決這個問題。 加入一些組件綁定後:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
<bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
它仍然沒有工作...:| 錯誤消息是類似於:
System.IO.FileLoadException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
文件名: 'System.Data.SqlServerCe,版本= 3.5.0.0,文化=中性公鑰= 89845dcd8080cc91'
我走了解。任何人?
編輯2:
1.I已經從我的機器上卸載了所有的微軟 「SQL Server精簡版」 的版本。
2.我檢查了machine.config版本:DbProviderFactories部分沒有條目。
3。我從there下載了3.5 SP2驅動程序並安裝了x86軟件包。
4,我檢查我的machine.config(V4 X86)和下面的條目已經在DbProviderFactories節點下創建:
<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
爲什麼是3.5.0.0,而不是3.5.1.50 ???
正確的案例:我的開發機器在Win7 x64上,目標機器是WinXP x86。
檢查這篇文章http://blogs.msdn.com/b/stevelasker/archive/2008/10/22/privately-deploying-sql-server-compact-with-the-ado-net -entity-provider.aspx – 2012-04-24 15:09:01
它看起來更好但是我仍然有一個彙編錯誤。 – JackoBongo 2012-04-25 10:19:52
檢查您的項目平臺是否設置爲「x86」。這個問題可能來自你的app.config。檢查連接字符串。 – 2012-04-25 10:27:06