A portal application

zhshqzyc
zhshqzyc used Ask the Experts™
on
Hi I have two sql server instances, one is normal and the other is backup mode that is the replication of the normal.

I have a portal in the web site. For a specific group in database and users in AD can login in backup mode. For others, they can login normal one.
Now I am using configuration file to swith the connection strings manully.

How to do it automatelly with code?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I would assume you have some way to detect which user they are. If that is the case:

<connectionStrings>
<add name="LiveDBConnection" connectionString="MyLiveConnection"/>
<add name="BackupDBConnection" connectionString="MyBackupConnection"/>
</connectionStrings>


if(Session["IsBackupUser"])
    connection.ConnectionString = ConfigurationManager.ConnectionStrings["BackupDBConnection"].ConnectionString
else
    connection.ConnectionString = ConfigurationManager.ConnectionStrings["MyLiveConnection"].ConnectionString

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial