Reputation: 39
can i have two different connection string in two different web config file in same web asp.net application?
I know that one asp.net project can have two web.config file in different directory of the project, But I want to add one connection string in one config file and another connection string in another config file in the same asp.net projcet
Upvotes: 3
Views: 1514
Reputation: 1636
Yes you can do it !
You can keep different names for connection string. You have to make sure that you are not overriding the connection string by keeping the same names.
<connectionStrings>
<add name="Test" connectionString="DataSource=MyDataSource;Initial
Catalog=MC1;User ID=Test; Password=Demo;" />
<add name="Test1" connectionString="Data Source=MyDataSource;Initial
Catalog=MC2;User ID=Test1; Password=Demo;" />
<connectionStrings>
Upvotes: 0
Reputation: 103358
Yes this is possible.
If the connection strings have the same "name", then the one in the directory will override the one in the root folder.
See this article for more information on web.config hierarchy:
http://msdn.microsoft.com/en-us/library/ms178685.aspx
Upvotes: 4