I decided to move Entity Connection String
from app.config
to code. However after setting it up like this:
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;
}
I have an exception thrown Unable to load the specified metadata resource.
in .Designer.cs.
/// <summary>
/// Initialize a new EntityBazaCRM object.
/// </summary>
public EntityBazaCRM(string connectionString) : base(connectionString, "EntityBazaCRM")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
If I define .Name inside my Entity creator it throws another exception
"Other keywords are not allowed when the 'Name' keyword is specified." (System.ArgumentException) Exception Message = "Other keywords are not allowed when the 'Name' keyword is specified.", Exception Type = "System.ArgumentException"
I know I'm missing something that I have to change so that self generated code uses new connection string but where to look for it?
After reading this answers article and this blog I changed:
entity.Metadata = @"res://*/Data.System.csdl|res://*/Data.System.ssdl|res://*/Data.System.msl";
To:
entity.Metadata = "res://*/";
And it works :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With