I have a web application with web.config file and many class library project and some windows services with app.config file. In each config file, i am putting connection string hard coded. So now, i want, there should be connection srting only in main web.config file and not in each app.config file. And want to use connection string from web.config in app.config.
Asked
Active
Viewed 485 times
0
-
http://msdn.microsoft.com/en-us/library/ms229697(v=vs.90).aspx – Adriano Repetti Oct 24 '12 at 09:43
-
Not clear. can you please explain better. – Prasad Kanaparthi Oct 24 '12 at 09:58
-
This is in web.config. Now i want to pick this connection string value in each app.config dynamically. How to do this. And plz note, i want to update app.config only, so that i can pick value from app.config to pages. – Gaurav Gupta Oct 24 '12 at 10:14
2 Answers
0
If you want generalize stringconnection
section
for all applications you can set this section in machine config
.
Nota :
- Each application has config file, in her root.
- You can define also define different config files in diiferent folders in application
=>
if you want customize behavior of folder's element.
Link : http://msdn.microsoft.com/en-us/library/1xtk877y(v=vs.71).aspx

Aghilas Yakoub
- 28,516
- 5
- 46
- 51
-
I don't want to use machine config file. I want to get connection string value from web.config in app.config file. Is there any way to do this – Gaurav Gupta Oct 24 '12 at 10:04
-
Ok if you don't want use machine.config,you can use string connection from web.config when you open connection, with read file by this specific path – Aghilas Yakoub Oct 24 '12 at 11:52
-
path = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ); with this code you obtain specific path , and concat this path with your another config file, and you open connection with this resultant path – Aghilas Yakoub Oct 24 '12 at 11:53
0
If your class library is not executable project then you can remove the connection string from all class libraries and maintain connection string in web.config.
If your class library is not executable then you cannot read config values from class library also. It will refer the executable project config files. Read

Community
- 1
- 1

Prasad Kanaparthi
- 6,423
- 4
- 35
- 62
-
Ok but there are some services also which are using App.config file. So, How to use the connection string from web.config into app.config for these services in the same solution – Gaurav Gupta Oct 24 '12 at 10:20
-
This will help you. I had same question here http://stackoverflow.com/questions/13045958/unable-read-app-config-values-from-class-library – Prasad Kanaparthi Oct 24 '12 at 10:22