我是Entity Framework的新手。我在这里遇到了这个错误![在此输入图像描述] [1]
[1]:http://i.stack.imgur.com/rZcvf.jpg我想以程序方式建立连接字符串
SqlConnectionStringBuilder sqlBuilder =
new SqlConnectionStringBuilder();
sqlBuilder.DataSource = server;
sqlBuilder.InitialCatalog = database;
sqlBuilder.IntegratedSecurity = false;
sqlBuilder.PersistSecurityInfo = true;
sqlBuilder.UserID = "XXXX"
sqlBuilder.Password = "XXXXX";
string providerString = sqlBuilder.ToString();
EntityConnectionStringBuilder ucEntities =
new EntityConnectionStringBuilder();
ucEntities.Provider = "System.Data.SqlClient";
ucEntities.ProviderConnectionString = providerString;
ucEntities.Metadata = @"res://*/";
Console.WriteLine(ucEntities.ToString());
using (EntityConnection conn =
new EntityConnection(ucEntities.ToString()))
{
conn.Open();
Console.WriteLine("Just testing the connection.");
conn.Close();
}
我的Soulution包含20多个项目,我在Sturtup项目中定义了.edmx,以及上面的代码。我必须以编程方式组织连接字符串'因为我们有许多服务器。 App.cfg中定义的连接字符串工作正常