Amenti
Amenti

Reputation: 1560

Ado.Net Entity Framework: Dynamic Database Access

I want to use the Ado.Net Entity Framework in an application. But the application needs to be able to connect to different databases (albeit with the exact same structure) at runtime. Further it is a client application, it's running locally.

I did not find a way to do this. There are some questions regarding accessing different databases but the answers seem to center on modifying some config files which I cannot do when the application is deployed.

Thanks in advance.

Upvotes: 0

Views: 414

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364279

You must use different connection strings (you can pass connection string to the constructor of the context). You must somehow define these connection strings and the most common way is using configuration file. If you don't want to use configuration files user will have to specify parameters of the connection file in runtime and you will have to build correct connection strings.

There are some limitations for this scenario. Databases must be:

  • Exactly same. Any single difference in mapped table or mapped column can break the application.
  • Run on the same type of database server. If you are using EDMX file the database description stored in metadata is dependent on the database server. In case of SQL server the version (2005 or 2008) matters as well!

Upvotes: 1

Related Questions