Entity Framework for ASP.NET and connection strings

asp.net entity-framework

Question

I have just started playing with the ASP.NET MVC.

 <add name="ApplicationServices" connectionString="Data Source=localhost;Port=3306;Database=test;User id=root;Password=admin;" providerName="MySql.Data.MySqlClient" />
<add name="testEntities" connectionString="metadata=res://*/Models.testDB.csdl|res://*/Models.testDB.ssdl|res://*/Models.testDB.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;port=3306;database=test;User Id=root;password=admin&quot;" providerName="System.Data.EntityClient" />

VS automatically creates connection strings on web.config with the DB details when you add a ADO entity data model. The problem is that I use ASP.NET user/privileges schema which uses "ApplicationServices" connection string which exists by default. All of those tables as well as my application tables exists on the same DB. I want the DB details(host/user/pass) to come from a single connection string entry. Or even if there are multiple connection string entries is it possible to get the DB details alone from a single source.

I come from the PHP world and couldn't figure out how to get it done from the other similar threads that I had bumped into.

Thanks

1
6
4/16/2011 11:20:14 AM

Popular Answer

Use simple approach. Define only ApplicationServices in the configuration and build EF connection string in the application. ObjectContext offers constructors with EntityConnection or a connection string directly. Pass ApplicationService's connection string to the provider connection string part in EF connection string.

EF offers defining connection string in configuration part but in 90% situations the only part which will change is provider connection string. Information about csdl, ssdl and msl files will usually not change. The only reason to change those resources can be supporting multiple database providers and in such case provider connection string part will change as well. In my opinion many applications can have those resource paths hardcoded directly in related context.

1
4/16/2011 8:00:50 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow