I’m looking for a way to dynamically change what Database my LINQ 2 SQL objects are using. The general concept we’re going for is to create one MVC Application that can be used for many clients. The first parameter of the URL would be something like ‘Client’, so that request and all future requests use that Client’s specific database, as opposed to a hard-coded one. I’m not entirely sure if this is feasible, but it was a concept born from the fear of mixing data from separate clients.
I hope this isn’t too crazy of a question. Also, I don’t really have any code to show, because I have no idea where to start on this one. 🙁
Thank you!
Use the overload of the DataContext constructor that takes in a connection string. You can inject from the appSettings.config or web.config.