Reputation: 2877
I didn't find any useful information about this, so I will try here.
My approach is, to have different db connections on my test server and on my life server.
Right now I have one connection String
<connectionStrings>
<clear/>
<add name="my_life" ... />
</connectionStrings>
Important note I had to provide the name of my string to the AspNetSqlMembershipProvider and AspNetSqlRoleProvider
<roleManager>
<providers>
<remove name="AspNetSqlRoleProvider"/>
<add name="AspNetSqlRoleProvider"
connectionStringName="my_life" ... />
</providers>
</roleManager>
Is there a way to handle the db connection via env variable or maybe url?
Upvotes: 1
Views: 128
Reputation: 16
you can maintain multiple connection strings in a XML file with unique reference id and read this file to get the connection string dynamically in your code where ever you want.
Sample like
<ConnectionString>
<Connection>
<Id></Id>
<ConString></ConString>
</Connection>
</ConectionString>
Upvotes: 0
Reputation: 18127
I really prefer to use DB Aliases if you want only ip address of your db to be diferent. If you want to have different web.config with different configurations by environment you can use web.config transformations.
Check Web.config Transformation Syntax for Web Application Project Deployment
Upvotes: 1