我决定将Entity Connection String
从app.config
移动到代码中。然而,设置好像是这样的:
public static string GetConnectionString() {
string connection = "";
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
sqlBuilder.DataSource = dbServer;
sqlBuilder.InitialCatalog = dbInitialCatalog;
sqlBuilder.IntegratedSecurity = false;
sqlBuilder.UserID = dbUserName;
sqlBuilder.Password = dbPasswWord;
sqlBuilder.MultipleActiveResultSets = true;
EntityConnectionStringBuilder entity = new EntityConnectionStringBuilder();
// entity.Name = "EntityBazaCRM";
entity.Metadata = @"res://*/Data.System.csdl|res://*/Data.System.ssdl|res://*/Data.System.msl";
entity.Provider = "System.Data.SqlClient";
entity.ProviderConnectionString = sqlBuilder.ToString();
connection = entity.ToString();
return connection;
}
我遇到了一个异常,无法加载指定的元数据资源
,在.Designer.cs文件中。
/// <summary>
/// Initialize a new EntityBazaCRM object.
/// </summary>
public EntityBazaCRM(string connectionString) : base(connectionString, "EntityBazaCRM")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
如果我在实体创建器中定义名称(.Name),它会抛出另一个异常:“当指定“Name”关键字时,不允许使用其他关键字。”(System.ArgumentException) 异常消息 = "Other keywords are not allowed when the 'Name' keyword is specified.", 异常类型 = "System.ArgumentException"。我知道我缺少某些东西,必须更改自动生成的代码以使用新的连接字符串,但要在哪里寻找呢?