我正在使用这样的代码,但我得到一个例外:“基础提供程序在打开时失败了。”可能的原因是什么?我已在app.config
文件中注释了连接字符串。
SqlConnectionStringBuilder sqlConnection = new SqlConnectionStringBuilder();
sqlConnection.DataSource = dataSource;
sqlConnection.InitialCatalog = initialCatalog;
sqlConnection.IntegratedSecurity = true;
EntityConnectionStringBuilder entityConnection = new EntityConnectionStringBuilder();
entityConnection.Provider = "System.Data.SqlClient";
entityConnection.Metadata = "res://*/Restaurant.csdl|res://*/Restaurant.ssdl|res://*/Restaurant.msl";
entityConnection.ProviderConnectionString = sqlConnection.ToString();
using (EntityConnection conn = new EntityConnection(entityConnection.ToString()))
{
conn.Open();
MessageBox.Show("Just testing the connection.");
conn.Close();
}