Q:

ASP.NET MVC3 Multiple Databases

Hello all:
I'm building an app using C#/MVC3/Razor which has a database configured in web.config. One of the requirements is to push the data to another database. is this doable within the MVC3 framework or should i just connect to the second database using standard methods/sql/?
thanks

A:

You could have a second connection string in your web.config and configure your ORM framework or whatever you are using to access those databases to use this second connection string:
<connectionStrings>
    <add name="db1" connectionString="Data Source=serverName;Initial Catalog=dbName1;User Id=foo;Password=secret;" providerName="System.Data.SqlClient" />
    <add name="db2" connectionString="Data Source=otherServerName;Initial Catalog=dbName2;User Id=bar;Password=secret;" providerName="System.Data.SqlClient" />
</connectionStrings>

Just one thing to remember: the ADO.NET Connection Pool is per App Domain and per connection string meaning that two separate connection pools will be held in this case.

