Hi folks,
Wondered if anyone out there could help me with a problem I am having.
I am developing a web site to be used by several different clients. Each client insists on their data being held in a separate database to other clients, so I am hoping to be able to have one web site, and then in the web.config file have a different ConnectionString for each client, each pointing to a different database in a back end SQL Server.
I want to hold the login information for each client in their own data database (by ensuring the tables in the default security database ASPNETDB.mdf file are in their own database).
At runtime, I want the client to specify what there account number is when they initially open the web site, and on entering this, the pages that display data from the database use the account number to dynamically change the data source to the correct database. I can get this part to work, simply by changing the SQLDataSource of say a GridView at runtime in the Page_Load event, so that side of things works nicely.
My problem come when the user logs in. I have a single "LocalSqlServer" ConnectionString setting in the web.config file, which has a connection string as follows:-
"Data Source=mySqlServer;Initial Catalog=MyDefaultSecurity;Trusted_Connection=True"
Because I want to hold login info for each client in their own database, at runtime when they have entered their account number, I want to change the connection string of the LocalSqlServer to something like:-
"Data Source=mySqlServer;Initial Catalog=Acc1234;Trusted_Connection=True"
where the clients database is called
Acc1234 (i.e. they have entered Acc1234 when they initally open the web site).
I don't seem to be able to change the connection string for LocalSqlserver initially stored in the web.config file, as I get an error "configuration is read only".
However, I have seen code in the professional ASP.Net 3.5 book that seems to suggest you can dynamically change connection strings at runtime, but this seems to throw up the read only error mentioned above.
Is there any way I can do this, or am I going to have to have a separate web site for each client, each with their own web.config file with the LocalSqlserver connection string pointing to their own database?
Any help anyone could give would be really appreciated.
Just in case it's relevant, I am using Microsoft's Visual Web Developer 2008 Express edition, with a backend SQL Server Developer Edition, and I code in
Vb.Net (not C#).
Kind regards,
Matt