0

I'm working with EntityFramework 5.0 and MySql. I have generated model from database, and my application now have to connect on multiple database with same structred data. So i have to dynamic change connection string based on some info.

I try to change database name even from config section of connection string, and with EntityConnectionStringBuilder, but i had the same result: my new connection is stored correctly, but data returned are of the first database.

From WebConfig:

add name="dbIncassiEntities" connectionString="metadata=res:///DAL.Modelincassi.csdl|res:///DAL.Modelincassi.ssdl|res://*/DAL.Modelincassi.msl;provider=Devart.Data.MySql;provider connection string="user id=root ... database=dbname2"" providerName="System.Data.EntityClient" />

From code:

EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = providerName;
entityBuilder.ProviderConnectionString = "user id=...database=dbname2";
entityBuilder.Metadata = @"res://*/DAL.Modelincassi.csdl|res://*/DAL.Modelincassi.ssdl|res://*/DAL.Modelincassi.msl";
var context = new dbIncassiEntities(entityBuilder.ToString());

My constructor:

public dbIncassiEntities(string conn)
    : base(conn)
{
}

What am i missing?

UPDATE

I can see that calling a query directly from SqlQuery, results returned are correct, while using the generated entities i retrieve wrong data.

 var test = context.Database.SqlQuery<string>(
                   "SELECT cognomenome FROM addetto limit 0,1").ToList();

But calling..

var oAddetto = from c in context.addettoes select c;

So my problem is only on the model itsself, and manually changing the generated schema

<EntitySet Name="addetto" EntityType="dbIncassiModel.Store.addetto" store:Type="Tables" Schema="dbname2" />

..i'll get the right information.

My question now is: how can i change in code these informations?? Any help is really appreciated!!

Thanks, David

4
  • Are you running on IIS? (Or: do the changes in web.config reset the web app? Or: does restarting the app help?) Commented Oct 22, 2013 at 14:14
  • Hi @Gert, yes i use iis express (i'm in local), but i was checking for a solution from days, without any answer.. So i turn off the pc, and so IIS and App. Thanks Commented Oct 22, 2013 at 14:20
  • You arent really showing the code where you set your connectionstring to your entitymodel, from code. Commented Oct 22, 2013 at 14:40
  • Hi @Rand.. i have updated the section "From code". Thanks Commented Oct 22, 2013 at 14:53

2 Answers 2

0

Ok, i've found a workaround for now.

I simply clear the shema name on the designer, and now i can call the generated entities succesfully. Hope this can help anyone else.

David

Sign up to request clarification or add additional context in comments.

Comments

0

While I could not remove the Schema in the designer, I removed it directly in the .edmx file. Do a full text search for Schema="YourSchema" in an XML editor of your choice and remove the entries. After that, changing the connection string is enough.

Downside is, the Visual Studio designer and mapping explorer won't work properly anymore.

This seems to be more of a dotConnect issue rather than MySQL, since the problem also exists for the Oracle adapter: http://forums.devart.com/viewtopic.php?t=17427

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.