使用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="
data source=SERVER;initial catalog=DATABASE;ID=USER;Password=PASSWORD;multipleactiveresultsets=True; Persist Security Info=True; Pooling=False;
App=EntityFramework"" providerName="System.Data.EntityClient" />
错误='基础提供程序在ConnectionString上失败'
答案 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="
data source=SERVER;initial catalog=DATABASE;User ID=USER;Password=PASSWORD;multipleactiveresultsets=True; Persist Security Info=True; Pooling=False;
App=EntityFramework"" providerName="System.Data.EntityClient" />