I have two solutions, one is a class library and the other is a web application, and I want to get the connection string from the web.config file to the class library as I am developing a custom membership provider. I am using Framework 4.0 and MS Visual Studio
2010.
Where you put "KeyName" I put the connection string name?
Yes...
suppose web.config of asp.net web project has conenction string as
<connectionStrings> <add
name="ConnectionString"connectionString="your connection string details"/> </connectionStrings>
then, in class library project u can read it as
Coqmos
Member
7 Points
8 Posts
Accessing Web.Config from a separate solution
Mar 27, 2012 03:42 PM|LINK
Hi,
I have two solutions, one is a class library and the other is a web application, and I want to get the connection string from the web.config file to the class library as I am developing a custom membership provider. I am using Framework 4.0 and MS Visual Studio 2010.
Thanks
kedarrkulkar...
All-Star
34535 Points
5554 Posts
Re: Accessing Web.Config from a separate solution
Mar 27, 2012 03:47 PM|LINK
you should be able to use
ConfigurationManager.AppSettings["KeyName"]
inside class library project and it should read web.config file of refernecing asp.net web project
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
Coqmos
Member
7 Points
8 Posts
Re: Accessing Web.Config from a separate solution
Mar 27, 2012 04:24 PM|LINK
Where you put "KeyName" I put the connection string name?
kedarrkulkar...
All-Star
34535 Points
5554 Posts
Re: Accessing Web.Config from a separate solution
Mar 27, 2012 04:36 PM|LINK
Yes...
suppose web.config of asp.net web project has conenction string as
<connectionStrings>
<add name="ConnectionString" connectionString="your connection string details" />
</connectionStrings>
then, in class library project u can read it as
string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
Coqmos
Member
7 Points
8 Posts
Re: Accessing Web.Config from a separate solution
Mar 27, 2012 05:39 PM|LINK
Yes but the web.config file is not in the same solution and not in the same directory also so I need to add some kind of reference I think to iy
kedarrkulkar...
All-Star
34535 Points
5554 Posts
Re: Accessing Web.Config from a separate solution
Mar 27, 2012 06:58 PM|LINK
suppose u r simple creating a class library (dll) then u can use this code to read web.config connectionstring...
when u add this dll in web application project, this code would read web.config where this dll is referenced
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
Coqmos
Member
7 Points
8 Posts
Re: Accessing Web.Config from a separate solution
Apr 01, 2012 04:13 PM|LINK
Hi,
Sorry For the late reply but I was away and did not have time to respond, jus to check, if in my dll I Do
connString = System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationString"].ConnectionString;
It should get the connection string?
Sorry but as you can see I am still a Beginner.
Thanks A Lot and I apolagize again for the late reply
kedarrkulkar...
All-Star
34535 Points
5554 Posts
Re: Accessing Web.Config from a separate solution
Apr 02, 2012 05:02 AM|LINK
Yes... it should
why dont u try
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
Coqmos
Member
7 Points
8 Posts
Re: Accessing Web.Config from a separate solution
Apr 02, 2012 01:19 PM|LINK
Thanks Very Much For your Help it worked out Great
Thanks Again For your help