SQL Server CE上的实体框架,无需安装驱动程序 [英] Entity Framework on SQL Server CE without driver install

查看:341
本文介绍了SQL Server CE上的实体框架,无需安装驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Entity Framework 4和SQL Server CE数据库3.5开发一个WPF应用程序,并正确运行。



然而,我想让这个应用程序在安装.Net Framework 4的机器上运行,但没有 SQL Server Compact 3.5 驱动程序。没有安装程序。有可能吗?



我尝试过以下操作:


  1. 在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 =& quot; Data Source = | DataDirectory | \Data\Database1.sdf& quot;
    providerName =System.Data.EntityClient/>
    < / connectionStrings>
    < system.data>
    < DbProviderFactories>
    < add name =SQL Server Compact Edition数据提供者
    invariant =System.Data.SqlServerCe
    description =。Microsoft SQL Server Compact Edition的.NET Framework数据提供者
    type =System.Data.SqlServerCe.SqlCeProviderFactory,System.Data.SqlServerCe,Version = 9.0.242.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91/>
    < / DbProviderFactories>
    < /system.data>
    < / configuration>


  2. 添加对 System.Data.SqlServerCe System.Data.SqlServerCe.Entity 并允许本地复制


  3. 构建应用程序,将其复制到没有安装SQL Server CE驱动程序的机器上。在创建数据上下文时,我不断得到这个错误:





系统。 ArgumentException:在配置中找不到指定的存储提供程序,或无效。 --->

System.ArgumentException:无法找到请求的.Net框架数据提供程序。可能没有安装。


我失去了时间吗?或者我应该切换到SQLite?



谢谢!



编辑: / p>

感谢josemiguel.torres的回答,请查看这篇文章 detailling如何实现这一点。但是,我仍然有一个程序集错误。

 System.IO.FileLoadException:无法加载文件或程序集System.Data .SqlServerCe,Version = 3.5.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91'或其中的一个依赖项定位程序集的清单定义与程序集引用不匹配
(HRESULT异常:0x80131040)

所以我看了一下这个其他的帖子解释如何解决这个问题。
添加一些程序集绑定后:

 < runtime> 
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =System.Data.SqlServerCepublicKeyToken =89845dcd8080cc91culture =neutral/>
< bindingRedirect oldVersion =3.5.1.0-3.5.1.50newVersion =3.5.1.50/>
< / dependentAssembly>
< / assemblyBinding>
< / runtime>

它仍然不起作用...:
错误消息类似:

  System.IO.FileLoadException:无法加载文件或程序集System.Data。 SqlServerCe,Version = 3.5.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91或其依赖关系之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT的异常:0x80131040)

文件名:'System.Data.SqlServerCe,Version = 3.5。 0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91'





我没有解决方案。任何人?



编辑2:



1.我已卸载所有的Microsoft我的机器上的SQL Server Compact Edition版本。



2.我检查了machine.config版本:DbProviderFactories部分中没有条目。



3我从那里下载了3.5 SP2驱动,并安装了x86



4.我检查我的machine.config(v4 x86),并在DbProviderFactories节点下创建了以下条目:

 < add name =Microsoft SQL Server Compact Data Providerinvariant =System.Data.SqlServerCe.3.5description =.NET Framework Data Provider for Microsoft SQL Server Compacttype =System.Data.SqlServerCe.SqlCeProviderFactory,System.Data.SqlServerCe,Version = 3.5.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91/> 

为什么是3.5.0.0而不是3.5.1.50?



juste如果我的dev机器在Win7 x64上,目标机器是WinXP x86。

解决方案

我放弃了SQL CE 3.5并切换到4.0。它的工作正常,感谢这篇文章
谢谢Erik;)


I'm developing a WPF application using Entity Framework 4 and SQL Server CE database 3.5 and it's correctly working.

However I'd like to have this application to run on a machine with .Net Framework 4 installed but without the SQL Server Compact 3.5 drivers. And no installer. Is it possible?

I have tried the following:

  1. create a section in the 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=&quot;Data Source=|DataDirectory|\Data\Database1.sdf&quot;" 
               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>
    

  2. add references to System.Data.SqlServerCe and System.Data.SqlServerCe.Entity and allow local copy

  3. build the application and copy it on a machine without SQL Server CE drivers installed. When it comes to create the data context I keep getting this error :

System.ArgumentException: The specified store provider cannot be found in the configuration, or is not valid. --->
System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.

Am I losing time? Or should I just switch to SQLite?

Thanks!

EDIT:

Thanks to josemiguel.torres' answer, I check at this post detailling how to achieve this. However, I still have an assembly error.

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

So I had a look at this other post explaining how to fix this issue. After adding some assembly binding:

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

It still doesn't work ... :| Error message is similar :

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)

File name: 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'

I'm out of solution. Anyone?

EDIT 2:

1.I have uninstalled all the Microsoft "SQL Server Compact Edition" versions from my machine.

2.I checked the machine.config version : there is no entries in the DbProviderFactories section.

3.I downloaded the 3.5 SP2 drivers from there and installed the x86 package.

4.I check my machine.config (v4 x86) and the following entries has been created under the DbProviderFactories node:

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

Why is it 3.5.0.0 and not 3.5.1.50???

juste in case: my dev machine is on Win7 x64 and target machine is WinXP x86.

解决方案

I gave up with SQL CE 3.5 and switched to 4.0. It's working fine, thanks to this article. Thanks Erik ;)

这篇关于SQL Server CE上的实体框架,无需安装驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆