Home All Groups Group Topic Archive Search About

Configuration problem

Author
25 Dec 2006 2:24 PM
Rastko Soskic
I have trouble reading configuration files (configuration for class library
(dll) project).
Although I've added configuration file and properly added configuration
file,
when I try to obtain settings via configuration manager.... simply I can't.
For example ConfigurationManager.ConnectionStrings["SomeName"] is always
null, although there is properly added connectionstring with "SomeName"
name.

What could be problem? configuration files are not available for dll
project???
Any help is appreciated. Thanks in advance :)

Author
25 Dec 2006 3:00 PM
Rastko Soskic
I've figured out what is problem. But how to solve it?

I have config file for DLL and web.config for website (DLL is middle tier
for site).

In class in DLL there is line:
ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString

"ConnString" is name within dll's config file (assemblyname.dll.config
right?) but

it looks like dll is reading web.config instead of dll.config? I understand
that is because .NET framework

searches for first config file in folder tree and web.config is first... How
to tell him to read dll's config file?
Maybe you have better idea? Thanks again :)

P.S. Maybe I should include Settins instead of config file? Is that good
solution/option?

Show quote
"Rastko Soskic" <rsos***@statserb.sr.gov.yu> wrote in message
news:%23Uuv2EDKHHA.1064@TK2MSFTNGP04.phx.gbl...
>I have trouble reading configuration files (configuration for class library
>(dll) project).
> Although I've added configuration file and properly added configuration
> file,
> when I try to obtain settings via configuration manager.... simply I
> can't.
> For example ConfigurationManager.ConnectionStrings["SomeName"] is always
> null, although there is properly added connectionstring with "SomeName"
> name.
>
> What could be problem? configuration files are not available for dll
> project???
> Any help is appreciated. Thanks in advance :)
>
Author
26 Dec 2006 2:01 AM
Jeff Dillon
File/New ...Configuration file
Show quote
"Rastko Soskic" <rsos***@statserb.sr.gov.yu> wrote in message
news:ObO$IZDKHHA.1044@TK2MSFTNGP02.phx.gbl...
> I've figured out what is problem. But how to solve it?
>
> I have config file for DLL and web.config for website (DLL is middle tier
> for site).
>
> In class in DLL there is line:
> ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString
>
> "ConnString" is name within dll's config file (assemblyname.dll.config
> right?) but
>
> it looks like dll is reading web.config instead of dll.config? I
> understand
> that is because .NET framework
>
> searches for first config file in folder tree and web.config is first...
> How
> to tell him to read dll's config file?
> Maybe you have better idea? Thanks again :)
>
> P.S. Maybe I should include Settins instead of config file? Is that good
> solution/option?
>
> "Rastko Soskic" <rsos***@statserb.sr.gov.yu> wrote in message
> news:%23Uuv2EDKHHA.1064@TK2MSFTNGP04.phx.gbl...
>>I have trouble reading configuration files (configuration for class
>>library (dll) project).
>> Although I've added configuration file and properly added configuration
>> file,
>> when I try to obtain settings via configuration manager.... simply I
>> can't.
>> For example ConfigurationManager.ConnectionStrings["SomeName"] is always
>> null, although there is properly added connectionstring with "SomeName"
>> name.
>>
>> What could be problem? configuration files are not available for dll
>> project???
>> Any help is appreciated. Thanks in advance :)
>>
>
>
Author
26 Dec 2006 3:08 PM
Rastko Soskic
Maybe I wasn't clear enough.
1. I have dll project and dll project has its App.config in dll project
there is for example:

class ObjectInDll
{
    SqlConnection conn;
    public ObjectInDll( )
    {
        conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
        // THERE IS connection string element with "connString" name in
Dll's config file
    }
}
2. I have web site and web site has its web.config.
3. In page class Default.aspx.cs (let it be in Page_Load event)
    ObjectInDll oid = new ObjectInDll();
    // creation of ObjectInDll throws exception because THERE IS NO
connection string element with "connString" name within web.config.
So, my question is ( although I've solved problem by including Settings via
property page of project)
*** How to solve this, if it is possible,  without inclusion of Settings, or
if including Settings is good solution I can stop breaking my mind :))) (How
to make ConfigurationManager to read proper config file and not first he
steps on?) ***


Show quote
"Jeff Dillon" <jeffdil***@hotmail.com> wrote in message
news:%23p1yvGJKHHA.2232@TK2MSFTNGP02.phx.gbl...
> File/New ...Configuration file
> "Rastko Soskic" <rsos***@statserb.sr.gov.yu> wrote in message
> news:ObO$IZDKHHA.1044@TK2MSFTNGP02.phx.gbl...
>> I've figured out what is problem. But how to solve it?
>>
>> I have config file for DLL and web.config for website (DLL is middle tier
>> for site).
>>
>> In class in DLL there is line:
>> ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString
>>
>> "ConnString" is name within dll's config file (assemblyname.dll.config
>> right?) but
>>
>> it looks like dll is reading web.config instead of dll.config? I
>> understand
>> that is because .NET framework
>>
>> searches for first config file in folder tree and web.config is first...
>> How
>> to tell him to read dll's config file?
>> Maybe you have better idea? Thanks again :)
>>
>> P.S. Maybe I should include Settins instead of config file? Is that good
>> solution/option?
>>
>> "Rastko Soskic" <rsos***@statserb.sr.gov.yu> wrote in message
>> news:%23Uuv2EDKHHA.1064@TK2MSFTNGP04.phx.gbl...
>>>I have trouble reading configuration files (configuration for class
>>>library (dll) project).
>>> Although I've added configuration file and properly added configuration
>>> file,
>>> when I try to obtain settings via configuration manager.... simply I
>>> can't.
>>> For example ConfigurationManager.ConnectionStrings["SomeName"] is always
>>> null, although there is properly added connectionstring with "SomeName"
>>> name.
>>>
>>> What could be problem? configuration files are not available for dll
>>> project???
>>> Any help is appreciated. Thanks in advance :)
>>>
>>
>>
>
>

AddThis Social Bookmark Button