Page 1 of 1

How to connection multiple connection string (runtime)

Posted: Tue 04 Aug 2015 18:30
by nattaporn
1. use entity framework 6.1.3 / Devart version 8.3.264.4
2. use entity framework => Dbcontext / database first
3. I try change connection string use

var mysqlBuilder = new Devart.Data.MySql.MySqlConnectionStringBuilder();
mysqlBuilder.UserId = "****";
mysqlBuilder.Password = "******";
mysqlBuilder.Database = "developer";
mysqlBuilder.Host = "localhost";
mysqlBuilder.Port = ****;
mysqlBuilder.PersistSecurityInfo = true;
string providerString = mysqlBuilder.ToString();

var entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "Devart.Data.MySql";
entityBuilder.Metadata = @"res://*/Entities.DataModelEntities.csdl|res://*/Entities.DataModelEntities.ssdl|res://*/Entities.DataModelEntities.msl";
entityBuilder.ProviderConnectionString = providerString;

var uow = new DbContext(entityBuilder.ConnectionString);


database not change connection string use old database. how to change connection string run time.

Please help me
Thank you.

Re: How to connection multiple connection string (runtime)

Posted: Wed 05 Aug 2015 10:16
by Shalex
Your code looks to be correct. Why had you decided that current connection string was not changed? Please enable the dbMonitor tool to trace the database activity of your application. This should help to localize the issue.

It's more likely that there is the Schema attribute in the storage part of your model which is targeting to old database (you can check this via dbMonitor). If so, remove the Schema="xxx" attributes from your SSDL. This can be done in design time of Entity Developer.
As an alternative, it is possible to leave the schema name in *.edml file, but to turn off the generation of the schema name in run-time queries using the IgnoreSchemaName option of EF-provider configuration: http://blog.devart.com/new-features-of- ... orkarounds.

Re: How to connection multiple connection string (runtime)

Posted: Fri 28 Aug 2015 01:56
by nattaporn
Thank you for answer but i know about problem.
1. The solution click right file .edml and choose model setting.
2. uncheck Preserve schema name in storage.
3. Recreate Model can change database