Reading Connection String from a class Library
I have a .net class library 2.0 with an app.config with a connectionString section.
I have 01 Method that this class library exposes " string GetConnectionString(string name)
However even though the app.config in this class library has 3 connstrings it do开发者_StackOverflowes not read this config.exe.How can I make it read the app.config that resides withing this dll?
Again, Usually you will have a web or windows app with a config and it will all work. Mine is a special case I need to read the connectionstring within this class library.
How can I do it?
thanks a lot
Class libraries don't have app.configs. You might have a file in your class library project named app.config but it's not considered the application's configuration file. The only file that matters is the app.config of the .exe which uses your class library.
One possible solution is to move the definitions of the connection strings from your app.config file from your class library's project into your .exe's project.
Another option is to interact with the app.config as a standard xml document to retrieve the values you're looking for.
精彩评论