the class library would be referenced in web application and at runtime it is under appdomain which is web application and hence, you could get hold onto config file connectionstring
hope this helps...
Cheers!
KK
Please mark as Answer if post helps in resolving your issue
My Site
after re-reading u r first post... i now understand u r question... I suppose, u want to read connectionstring available in app.config of class library project instead of reading it from web.config of web application in which dll is referenced.
I thought u r question is exactly reverse and hence, my last post.
anyways... as i explained earlier, the dll runs under appdomain of web application and hence, configurationmanager will give u connectionstring from web.config.
i.e. there is no class library app.config at runtime... also, it is logical... since anyone can use the class library dll without having app.config with it.
u can use separate xml file... say config.xml and use xml read methods to read xml tags to get the connectionstring from it (dont use configmanager)
hope this helps...
Cheers!
KK
Please mark as Answer if post helps in resolving your issue
My Site
Marked as answer by moshik.salem on May 05, 2012 06:49 AM
moshik.salem
Member
34 Points
124 Posts
how to read a connection string from class library on 3-tier design
May 03, 2012 01:31 PM|LINK
hi,
i got a 3-tier design on my asp.net app,
i am trying to read a connection string which is located at the DAL class library, but i am getting a different one, and it is the only one that
the ConfigurationManager gives me. i think i am getting the default connection string.
My question: How do i get the connection string which i wrote on my app.config file on the DAL class library? and not the default?
Thank You.
keval.trived...
Member
158 Points
87 Posts
Re: how to read a connection string from class library on 3-tier design
May 03, 2012 01:37 PM|LINK
Hi,
make one file having extension <filename>.udl then save it.....
Now double click this file -> select provider -> select severname -> databasename -> test connection ->ok
Now open this file with notepad take whole string accept provider then set it to web config...
I think it work....
------------------------------------
Dont forgot to mark as answer
kedarrkulkar...
All-Star
34225 Points
5494 Posts
Re: how to read a connection string from class library on 3-tier design
May 03, 2012 01:40 PM|LINK
you can read connectionstring from config file in any of the class library files... like this
string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString
the class library would be referenced in web application and at runtime it is under appdomain which is web application and hence, you could get hold onto config file connectionstring
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
moshik.salem
Member
34 Points
124 Posts
Re: how to read a connection string from class library on 3-tier design
May 03, 2012 01:56 PM|LINK
hi,
i tried to read the connection string like you said but i think the web.config override the app.config file where the connection string is located.
do you how to overcome this overriding?
kedarrkulkar...
All-Star
34225 Points
5494 Posts
Re: how to read a connection string from class library on 3-tier design
May 04, 2012 06:08 AM|LINK
after re-reading u r first post... i now understand u r question... I suppose, u want to read connectionstring available in app.config of class library project instead of reading it from web.config of web application in which dll is referenced.
I thought u r question is exactly reverse and hence, my last post.
anyways... as i explained earlier, the dll runs under appdomain of web application and hence, configurationmanager will give u connectionstring from web.config.
i.e. there is no class library app.config at runtime... also, it is logical... since anyone can use the class library dll without having app.config with it.
u can use separate xml file... say config.xml and use xml read methods to read xml tags to get the connectionstring from it (dont use configmanager)
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
moshik.salem
Member
34 Points
124 Posts
Re: how to read a connection string from class library on 3-tier design
May 05, 2012 06:54 AM|LINK
do you recommend to save the connection string in the web.config instead of th app.config???
beacuse according to what you wrote it is impossible to read my connection string from the app.config while there is another web.config
in another project on the solution, using the Configuration Manager?
kedarrkulkar...
All-Star
34225 Points
5494 Posts
Re: how to read a connection string from class library on 3-tier design
May 08, 2012 05:06 AM|LINK
yes... that will do
KK
Please mark as Answer if post helps in resolving your issue
My Site