I personally use EntityFramework inside a project for connecting to some Mysql database. The provider is Devart Us dot.connect.

This application must connect with a database using connexion parameters distributed by the consumer at runtime. Including obviously the Mysql Database title.

I made use of the EntityConnectionStringBuiler and EntityConnection classes to construct-up and keep custom connexion parameters.

However , despite such given parameters, the applying always connect with the database named when creating the EntityModel while using visual studio wizard. What's very strange is the fact that when debuging and checking the status from the ObjectContext, the custom connexion parameters are properly used... It can make me mad !!!!! Any clue ?

After investing eventually about this problem, I finally found realize that the issue was from the model.edmx file.

Within this file, you've one line per EntitySet. On each EntitySet element there's a characteristic known as schema. Just in case of SQL Server this attribute is placed towards the related table schema :

EntitySet Title="annee_civile" EntityType="openemisModel.Store.annee_civile" store:Type="Tables" Schema="mydatabase" />

Should you supply the title from the Schema when constructiong you have EntityConnection, it appear that there's a conflict which finally, the Schema defined within the edmx file is going to be used even when you specified a different one within the connection parameters.

The answer is just to get rid of the title from the schema within the edmx file. THIS Works Best For MYSQL, most likely not when hooking up to some SQL server.

EntitySet Title="annee_civile" EntityType="openemisModel.Store.annee_civile" store:Type="Tables" Schema="" />

The EntityConnectionStringBuilder :

string providedString = "User Id=xxxxPassword=xxxHost=xxxxDatabase=anydatabasename" EntityConnectionStringBuilder entityConnBuilder = new EntityConnectionStringBuilder() entityConnBuilder.Provider = "Devart.Data.MySql" entityConnBuilder.Metadata = @"res:///OpenEmisModel.csdlres:///OpenEmisModel.ssdlres://*/OpenEmisModel.msl" entityConnBuilder.ProviderConnectionString = providedString

The EntityConnection and also the object context utilizing it:

EntityConnection entityConnexionEmis = new EntityConnection(entityConnBuilder.ConnectionString)

objectcontextEntities testingContext = new objectcontextEntities(entityConnexionEmis)

The program is now connect with any database title.

Hope this can help.