SqlCe 4.0 + EF 5.0在VS2012中停止工作 [英] SqlCe 4.0 + EF 5.0 stopped working in VS2012

查看:167
本文介绍了SqlCe 4.0 + EF 5.0在VS2012中停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了几乎可以分发给客户端的应用程序。花了我几个月的时间。一切都很好,但是我安装了VS2012,所有的测试都停止工作。我尝试了一切,但终于放弃了重新安装了我的整个电脑。



与以前相同的设置,但一切都很干净:Windows 7 64bit,VS2012,SQL2012等。好,所以我很高兴但是现在我遇到了一个新的麻烦。当瞄准SqlCe 4.0它不起作用。我的应用程序将通过WinApi与中央SQL Server进行同步。那部分是好的,但是使用SqlCe 4.0的本地数据库不起作用。问题是什么?这是一个新的干净的电脑!



我创建了一个新的基本设置的新解决方案:Nuget安装了SqlCe Compact,Entity Framework 5,代码第一,一个类,一个上下文。这是行不通的!它被卡在第一次上下文调用数据库,而不会生成数据库文件。没有例外,只是卡住了!



发生了什么事? SqlCe不可靠吗?我应该切换到SQLite吗?问题是我有很多代码,我非常习惯于EF。

解决方案

我没有找到与我的案例完全匹配的答案。但是我在blog.config文件中提到了一个坏的形成标签的博客。当看到它时,我发现这个非常关键的部分:

 < system.data> 
< DbProviderFactories>
< add name =Odbc Data Providerinvariant =System.Data.Odbcdescription =。用于Odbc的Net Framework数据提供者type =System.Data.Odbc.OdbcFactory,System.Data,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089/>
< add name =OleDb Data Providerinvariant =System.Data.OleDbdescription =。OleDb的Net Framework数据提供者type =System.Data.OleDb.OleDbFactory,System.Data,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089/>
< add name =OracleClient Data Providerinvariant =System.Data.OracleClientdescription =.Net Framework Data Provider for Oracletype =System.Data.OracleClient.OracleClientFactory,System.Data.OracleClient ,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089/>
< add name =SqlClient Data Providerinvariant =System.Data.SqlClientdescription =.SqlServer的Ne​​t Framework数据提供者type =System.Data.SqlClient.SqlClientFactory,System.Data,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089/>
< add name =Microsoft SQL Server Compact Data Provider 4.0invariant =System.Data.SqlServerCe.4.0description =.NET Framework Data Provider for Microsoft SQL Server Compacttype =System.Data SqlServerCe.SqlCeProviderFactory,System.Data.SqlServerCe,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91/>
< 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/>
< / DbProviderFactories>
< /system.data>

在我的machine.config文件中,DbProviderFactories部分为空。我试图添加它但是不能,因为它被一些应用程序锁定。另一方面,我的客户可能遇到同样的问题,我很难让他们编辑machine.config。所以我做了这个简单的方法:将部分添加到我的应用程序配置文件!瞧!一切恢复正常。我的应用程序再次运行得很好。



但是为什么在我以前的Windows安装中工作?为什么这个部分不总是添加到machine.config?为什么DbProviderFactory从未被提及作为SqlCe 4.0与EntityFramework 5.0结合使用的演示样本的先决条件?这可能只是.NET Framework 4.5中的问题?


I have created an application almost ready to distribute to clients. It took my several months. Everything worked fine but then I installed VS2012 and all my tests stop working. I tried everything but finally gave up and reinstalled my whole computer.

Same setup as before but everything clean: Windows 7 64bit, VS2012, SQL2012, etc. Now all tests worked fine so I was happy. But now I ran into a new trouble. When targeting SqlCe 4.0 it does not work. My application will sync with a central SQL Server through WinApi. That part was fine, but the local database with SqlCe 4.0 just does NOT work. What is the problem? It is a new clean computer!

I created a fresh new solution with basic setup: Nuget installed SqlCe Compact, Entity Framework 5, code first, one class, one context. It does not work! It is stuck on first context call to database and database file is not generated. No exception, just stuck!

What is going on? Is SqlCe not reliable? Should I switch to SQLite? Problem is I have lots of code and I am very used to EF.

解决方案

I searched without finding an answer exactly matching my case. But I got an idea on a blog mentioning a bad formed tag in the machine.config file. When looking in it I found this very crucial section:

  <system.data>
    <DbProviderFactories>
      <add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
      <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"/>
    </DbProviderFactories>
  </system.data>

In my machine.config file the section DbProviderFactories was empty. I tried to add it but was not able, because it was locked by some application. On the other hand my customers may run into the same problem and it is difficult for me to have them edit machine.config. So I did it the easy way: added the section to my application config file! Voila! Everything is back to normal. My application runs beautifully again.

But why did it work in my previous Windows installation? Why is this section not always added to machine.config? Why is DbProviderFactories never mentioned as a prerequisite in demo samples on SqlCe 4.0 in combination with EntityFramework 5.0? Is this maybe just a problem in .Net Framework 4.5?

这篇关于SqlCe 4.0 + EF 5.0在VS2012中停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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