实体框架连接字符串在Windows应用程序中不起作用

时间:2013-03-11 07:21:28

标签: c# sql sql-server-2008

使用EF连接到客户端的数据库时遇到一些问题。

我可以使用连接字符串进行连接...

SqlConnection thisConnection = null;

string connection = "Data Source=SERVER; Initial Catalog=DATABASE; User ID=USER; Password=PASSWORD; Persist Security Info=True; Pooling=False;"

 thisConnection = new SqlConnection(string.Format(connection));
 thisConnection.Open();

但是,当我使用EF并将我的app.config更新为下面的连接字符串时,我无法连接...任何提示?

<add name="dbEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;
     provider=System.Data.SqlClient;provider connection string=&quot;
     data source=SERVER;initial catalog=DATABASE;ID=USER;Password=PASSWORD;multipleactiveresultsets=True; Persist Security Info=True; Pooling=False;
     App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

错误='基础提供程序在ConnectionString上失败'

1 个答案:

答案 0 :(得分:1)

在EF中,用户名密钥应为User ID(不是ID

所以

<add name="dbEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;
     provider=System.Data.SqlClient;provider connection string=&quot;
     data source=SERVER;initial catalog=DATABASE;User ID=USER;Password=PASSWORD;multipleactiveresultsets=True; Persist Security Info=True; Pooling=False;
     App=EntityFramework&quot;" providerName="System.Data.EntityClient" />