0

I wonder if I can have multiple connection on entity model such as -

using (var db = new VWEntitiesModel("data source=Dev;initial catalog=Website1;user id=sqluser;password=&&password"))
{
    some logic
}

using (var db = new VWEntitiesModel("data source=Dev;initial catalog=Website2;user id=sqluser;password=&&password"))
{
    some logic
}

I'm using Telerik Openaccess Entity model. I tried to use as above. It seems like it doesn't like it. Any advice please ?

alwayslearning
  • 4,493
  • 6
  • 35
  • 47
Tun
  • 824
  • 3
  • 16
  • 30
  • When you are saying that *it does not like it* could you be a little more precise about this dislike? What form does it have? Maybe an error message or something? – Darin Dimitrov Oct 12 '12 at 14:45
  • I am not familiar with Telerik OpenAccess in particular, however, I would say it's a major limitation if you couldn't. Regardless, this code is synchronous therefore you technically wouldn't be opening up 2 separate connections you would be closing the first before you open the 2nd. – James Oct 12 '12 at 15:04
  • Actually I having this error on WCF service. I have wcf service and console app. Bascially wcf service reads multiple databases and send emails. The console app will call wcf service every hours. – Tun Oct 12 '12 at 15:08

1 Answers1

0

An EntityModel (OpenAccessContext derived type) represents the conceptual model that is mapped to tables in the database. The difference in the connection strings that you have specified above is the 'Initial Catalog'. To work with the same model against two different databases would require them to be exactly the same as far as the objects (tables,column,constraints etc) known to the domain model are concerned.

You can specify two unique connection strings but this would result in OpenAccess maintaining a unique workspace (metadata,caches,connection pool etc) for each unique connection string that you use.

If your service is querying two different databases you should have two independent domain models that represent the databases and instantiate them with the appropriate connection string.

alwayslearning
  • 4,493
  • 6
  • 35
  • 47