From: Ele on
Hello,

I have one solution containing two c# projects: one project builds a DLL
that is used by the main project (the other project). In the web.config of
the main project I added (in the appSettings section) the connectionString
parameter, that I read to load my connection string (to SQL Server 2005).

However, in the supporting project (the DLL), sometimes I need to connect to
the database too. But I don't have the connection string there, and I don't
want to duplicate it (in some constant inside the DLL). Sure, I can pass the
connectionString each time I call a method/function in the DLL, but I think
this is not a good way.

So my question is: what is the best way to share the connectionString
between the main project and the DLL?

Thanks!


From: sloan on

The referenced assembly will have access to the presentation layer's web (or
app).config file.

You can see it in action via this example:
http://sholliday.spaces.live.com/blog/cns!A68482B9628A842A!140.entry
(Code is downloadable)

You can also look here:
http://www.eggheadcafe.com/tutorials/aspnet/e54f2d32-72c4-4d2b-b180-c1f564b41f85/some-aspnet-20-configur.aspx



"Ele" <nospam(a)nospam.com> wrote in message
news:4b83da9b$0$1129$4fafbaef(a)reader3.news.tin.it...
> Hello,
>
> I have one solution containing two c# projects: one project builds a DLL
> that is used by the main project (the other project). In the web.config of
> the main project I added (in the appSettings section) the connectionString
> parameter, that I read to load my connection string (to SQL Server 2005).
>
> However, in the supporting project (the DLL), sometimes I need to connect
> to the database too. But I don't have the connection string there, and I
> don't want to duplicate it (in some constant inside the DLL). Sure, I can
> pass the connectionString each time I call a method/function in the DLL,
> but I think this is not a good way.
>
> So my question is: what is the best way to share the connectionString
> between the main project and the DLL?
>
> Thanks!
>
>


From: sloan on
PS

My .Data (DataLayer) uses the config values from the presentation layer.




"sloan" <sloan(a)ipass.net> wrote in message
news:Obkh%23FJtKHA.712(a)TK2MSFTNGP04.phx.gbl...
>
> The referenced assembly will have access to the presentation layer's web
> (or app).config file.
>
> You can see it in action via this example:
> http://sholliday.spaces.live.com/blog/cns!A68482B9628A842A!140.entry
> (Code is downloadable)
>
> You can also look here:
> http://www.eggheadcafe.com/tutorials/aspnet/e54f2d32-72c4-4d2b-b180-c1f564b41f85/some-aspnet-20-configur.aspx
>
>
>
> "Ele" <nospam(a)nospam.com> wrote in message
> news:4b83da9b$0$1129$4fafbaef(a)reader3.news.tin.it...
>> Hello,
>>
>> I have one solution containing two c# projects: one project builds a DLL
>> that is used by the main project (the other project). In the web.config
>> of the main project I added (in the appSettings section) the
>> connectionString parameter, that I read to load my connection string (to
>> SQL Server 2005).
>>
>> However, in the supporting project (the DLL), sometimes I need to connect
>> to the database too. But I don't have the connection string there, and I
>> don't want to duplicate it (in some constant inside the DLL). Sure, I can
>> pass the connectionString each time I call a method/function in the DLL,
>> but I think this is not a good way.
>>
>> So my question is: what is the best way to share the connectionString
>> between the main project and the DLL?
>>
>> Thanks!
>>
>>
>
>


From: Ele on
"sloan" <sloan(a)ipass.net> ha scritto nel messaggio
news:Obkh%23FJtKHA.712(a)TK2MSFTNGP04.phx.gbl...
> The referenced assembly will have access to the presentation layer's web
> (or app).config file.
> You can see it in action via this example:
> http://sholliday.spaces.live.com/blog/cns!A68482B9628A842A!140.entry
> (Code is downloadable)

Thank you, I downloaded it. I saw that you have a file app.config containing
the configuration string. However I also see the comment:

<!-- Please note this is NOT the correct "2.0" way of setting up connection
strings -->

So, if that is not the correct way, what is the correct one? I'm using
framework 3.5.
Thanks! :-)



From: sloan on
See? Putting in comments does help in the long run.

Here are some links:


http://msdn.microsoft.com/en-us/library/htw9h4z3.aspx

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx

http://www.davidhayden.com/blog/dave/archive/2007/02/22/ReadConnectionStringsWebConfigAppConfig.aspx





"Ele" <nospam(a)nospam.com> wrote in message
news:4b8421c7$0$1120$4fafbaef(a)reader2.news.tin.it...
> "sloan" <sloan(a)ipass.net> ha scritto nel messaggio
> news:Obkh%23FJtKHA.712(a)TK2MSFTNGP04.phx.gbl...
>> The referenced assembly will have access to the presentation layer's web
>> (or app).config file.
>> You can see it in action via this example:
>> http://sholliday.spaces.live.com/blog/cns!A68482B9628A842A!140.entry
>> (Code is downloadable)
>
> Thank you, I downloaded it. I saw that you have a file app.config
> containing the configuration string. However I also see the comment:
>
> <!-- Please note this is NOT the correct "2.0" way of setting up
> connection strings -->
>
> So, if that is not the correct way, what is the correct one? I'm using
> framework 3.5.
> Thanks! :-)
>
>
>