无法在C#中连接数据库

时间:2015-10-27 04:59:17

标签: c# entity-framework

我实际上从项目中删除了以前的连接和模型并再次添加它们。但是,现在我无法再次连接到数据库。我验证了所有web.config和app.config中的连接字符串,但它们是相同的。

Web.config

<add name="AuthenticationAppEntities" 
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyPC;Initial Catalog=AuthenticationApp;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

另一个web.config

<add name="AuthenticationAppEntities" 
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyPC;Initial Catalog=AuthenticationApp;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

App.config

<add name="AuthenticationAppEntities"  
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyPC;Initial Catalog=AuthenticationApp;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

我不知道那里可能出现什么问题。有什么帮助吗?

当我启用公共语言运行时异常时,我收到此错误:

  

&#39;(db.Table)。当地&#39;抛出类型&#39; System.InvalidOperationException&#39;

的例外

1 个答案:

答案 0 :(得分:0)

检查这些链接,它可能对您有帮助。

http://forums.asp.net/t/1749216.aspx?Code+First+Entity+Framework+not+creating+tables+in+the+database

http://www.codeproject.com/Questions/299466/Code-First-Entity-Framework-not-creating-tables-in

How to handle System.InvalidOperationException in entity framework?

我正在使用类似下面的连接字符串

<add name="AuthenticationAppEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyPC;Initial Catalog=AuthenticationApp;User ID=xyz;Password=Password@1;MultipleActiveResultSets=True; App=EntityFramework&quot;" providerName="System.Data.EntityClient" />