Multiple Web.Config Files from ASP.NET Login Page

Posted by Souravagar under ASP.NET on 6/2/2015 | Points: 10 | Views : 1102 | Status : [Member] | Replies : 2
I need to implement an ASP.NET Web Forms Application which will have multiple Web.Config Files for different SQL Server Database like Staging, Testing, Development or Production.

We will have a login page which has Environment dropdown box to choose web.config files such as Testing, Dev, Staging, and Live. If we select staging then login will connect to staging connectionstring.

Please guide me how we can achieve that. Thank you.




Responses

Posted by: Jayakumars on: 6/3/2015 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi

No need Multiple webconfig this scenario becos we can use one webconfig just change connection block like this


<connectionStrings>
<add name="StagingConnection" providerName="System.Data.SqlClient"
connectionString="Data Source=PCNAME;Initial Catalog=DBNAME;Integrated Security=SSPI; User ID=myDomain\myUsername;Password=myPassword;" />

<add name="TestingConnection" providerName="System.Data.SqlClient"
connectionString="Data Source=PCNAME;Initial Catalog=DBNAME;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;" />

<add name="DevelopmentConnection" providerName="System.Data.SqlClient"
connectionString="Data Source=PCNAME;Initial Catalog=DBNAME;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;" />

<add name="ProductionConnection" providerName="System.Data.SqlClient"
connectionString="Data Source=PCNAME;Initial Catalog=DBNAME;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;" />
</connectionStrings>

refer this url for connectionstrings

http://www.connectionstrings.com/
https://www.connectionstrings.com/sql-server/


Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Souravagar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Souravagar on: 6/3/2015 [Member] Starter | Points: 25

Up
0
Down
My project has more than 40 classes and we are using the same connectionstring in all the classes.
for example:
<add name="ABCConnString" providerName="System.Data.SqlClient"
connectionString="Data Source=PCNAME;Initial Catalog=DBNAME;Integrated Security=SSPI; User ID=myDomain\myUsername;Password=myPassword;" />

I want that when user login into page based on the environment selection, I can replace the ConnectionString in the above web.config file.
If I am able to do so then I don't have to change the database connection settings anywhere in the project.
I can also use web.config transformation using multiple config files but I don't know how to use that in this scenario.

Souravagar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response