views:

249

answers:

1

Problems Background (you can skip to the question)

I have many ASP.Net websites which are same application. different database but same schema, in the same SQL Server.

The administration site is already implemented in each virtual directory, and I use subsonic for DAL.

  1. http://website1.com/admin
  2. http://website2.com/admin
  3. http://website3.com/admin
  4. will adding..

Now instead of creating an administration page for each website, I'm thinking about integrating/creating one site for administrate all these websites.

  1. http://websiteadmin.com/?website=1
  2. http://websiteadmin.com/?website=2
  3. http://websiteadmin.com/?website=3

Since I host the database in the same server and with same database schema, I think I only need to update connection string.

So The Question Is..

how can I switch the subsonic database connection on runtime?

// WebsiteDAL is the subsonic generated namespace
// I've tried to change database causing null error
WebsiteDAL.DB.Repository.Provider.CurrentSharedConnection.ChangeDatabase(db);

// also tried to add connection string and update on runtime, 
// but still no effect
WebsiteDAL.DB._provider.ConnectionStringName = "website1connectionstring";

// Records are still loaded from default connection
WebsiteDAL.SomeTables st = WebsiteDAL.SomeTables.FetchByID(1);
A: 

Take a look at this blog post: Setting Subsonic's connectionstring at runtime.

Justin Grant