Change connection on the fly

I have a SQL server with 50 databases. Each of them has the same layout. I used awesome Subsonic 2.2, building a DAL based on one of them.

I need to code a list of database names and connect to each one and update one at a time.

If there is a way to change how the subsonic connection string is used. I believe I will need to keep the connection string in memory in a way that it can change.

Is it possible?

I have tried doing

ConfigurationManager.ConnectionStrings["theConnStrName"].ConnectionString = updated-connection-string-here;

      

.. but it didn't work

thanks!

+2


a source to share


2 answers


Subsonic was developed mainly for one database only. I've made multiple databases in several ways. I posted a complete sample for creating providers on the fly in the old subsonic forums. Now these messages have disappeared. What you can try is to set up one provider in the config file (yourProviderName) with a dummy connection string just to initialize the subsonic and then set the actual connection string as needed in your code. This only works with one database at a time, but I think this is what you need. If you want to use multiple databases at the same time and include more code and some changes to the 2.x subsonic kernel.



DataProvider provider = DataService.GetInstance(yourProviderName);
foreach(string connString in connectionStrings)
{
    provider.DefaultConnectionString = connString;
    DataService.Provider = provider;
    // ... do stuff
}

      

+1


a source


I don't think it's easy to fix this without creating a SubSonic provider for each database.



Instead, I would put SubSonic source as a project in the solution and debug my way to the best and cleanest place to extend the code with some sort of wordlist and dictionary connnection functionality to set the one you want at a given time ...

+1


a source







All Articles