Reputation: 4951
I am currently working on a ASP .Net MVC 3 application to do some database manipulations on a specific set of Metadata tables in a database. I'll basically be doing inserts, updates deletes etc. from the application. However, the aim is to migrate these Metadata tables across different databases (and most likely servers as well) so that we can use the same Methodology across clients.
Right now I am using Linq2Sql to generate my ORM around these specific metadata tables. The aim is to use the same application to manipulate the data across servers and databases. What is the best practice/approach for this?
The simplest solution that I've thought of is a constructor for my DataContext
where I could use user input (server + database name +userID +password) to manipulate a connection string and pass it into my DataContext
. Since the Framework should be the same across all databases and servers, this should work in theory. However, I'm not where the best place to maintain the modified connection string is (The session? a cookie?).
What is the best practice around this kind of server/database switching in a .Net app?
Upvotes: 0
Views: 152
Reputation: 10418
You're going down the right path by passing the connection in the constructor for the context. As for maintaining the connection string, I suspect that would depend on how you are managing the other site information for your various sites. If you are managing that in a central database, save the site specific value in that central database and use the same persistance you are using for those site settings while the user is visiting your site. Just make sure not to pass server specific information to the client (thus a cookie would not be the recommended approach).
Upvotes: 1