Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 14, 2012 08:36 AM by mamun.cse@hotmail.com
Member
41 Points
133 Posts
Jan 27, 2009 02:52 PM|LINK
Hi;
my web application have a class library and me want to get ConnesctionString at web.config for my class library.
How can me do it?
Thanks,mohsen
Star
12726 Points
2245 Posts
Jan 27, 2009 03:34 PM|LINK
For good design you should pass it into your class from the web application.
Failing that you can use the System.Configuration namespace to access the web.config.
System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
Participant
1712 Points
294 Posts
Jan 27, 2009 04:25 PM|LINK
Hi Friend,
If are a C# user then import System.Configuration Namesapce in your class file first, Like....
using System.Configuration;
Now, Create the sql connection string like this code
SqlConnection connectionString = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString());
And then access that connection string in your class file where ever you want.
Sincerely, Pradeep Kr. Sharma
Please remember to click “Mark as Answer” on the post that helps you. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 Points
8 Posts
Dec 14, 2012 07:37 AM|LINK
Pradeep Kr. Sharma Hi Friend, If are a C# user then import System.Configuration Namesapce in your class file first, Like.... using System.Configuration; Now, Create the sql connection string like this code SqlConnection connectionString = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString()); And then access that connection string in your class file where ever you want. Sincerely, Pradeep Kr. Sharma Please remember to click “Mark as Answer” on the post that helps you. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hi guys!!
at this method AppSettings["ConnectionString"] , which parameter should I pass instead of "ConnectionString" ?!
thank you for your efficient reply!
Dec 14, 2012 08:22 AM|LINK
Iran-Girl at this method AppSettings["ConnectionString"] , which parameter should I pass instead of "ConnectionString" ?! thank you for your efficient reply!
I find the answer:
please follow it in http://stackoverflow.com/questions/7069911/how-to-use-the-configurationmanager-appsettings
84 Points
17 Posts
Dec 14, 2012 08:36 AM|LINK
At Web.config:
<connectionStrings> <add name="Constr" connectionString="Data Source=.\;Initial Catalog=DatabaseNamet;Integrated Security=True"/> </connectionStrings>
Add this namespace using System.Configuration;
var connectionString=ConfigurationManager.ConnectionStrings["Constr"].ConnectionString;
mohsendevelo...
Member
41 Points
133 Posts
Get ConnectionString at Web.config for class library
Jan 27, 2009 02:52 PM|LINK
Hi;
my web application have a class library and me want to get ConnesctionString at web.config for my class library.
How can me do it?
Thanks,mohsen
Mr^B
Star
12726 Points
2245 Posts
Re: Get ConnectionString at Web.config for class library
Jan 27, 2009 03:34 PM|LINK
For good design you should pass it into your class from the web application.
Failing that you can use the System.Configuration namespace to access the web.config.
System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
Pradeep Kr. ...
Participant
1712 Points
294 Posts
Re: Get ConnectionString at Web.config for class library
Jan 27, 2009 04:25 PM|LINK
Hi Friend,
If are a C# user then import System.Configuration Namesapce in your class file first, Like....
using System.Configuration;
Now, Create the sql connection string like this code
SqlConnection connectionString = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString());
And then access that connection string in your class file where ever you want.
Sincerely,
Pradeep Kr. Sharma
Please remember to click “Mark as Answer” on the post that helps you.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://vshelpdesk.blogspot.com/
Please Mark As Answer, which helped you. So that it might be useful for others.
Iran-Girl
Member
4 Points
8 Posts
Re: Get ConnectionString at Web.config for class library
Dec 14, 2012 07:37 AM|LINK
hi guys!!
at this method AppSettings["ConnectionString"] , which parameter should I pass instead of "ConnectionString" ?!
thank you for your efficient reply!
Iran-Girl
Member
4 Points
8 Posts
Re: Get ConnectionString at Web.config for class library
Dec 14, 2012 08:22 AM|LINK
I find the answer:
please follow it in http://stackoverflow.com/questions/7069911/how-to-use-the-configurationmanager-appsettings
mamun.cse@ho...
Member
84 Points
17 Posts
Re: Get ConnectionString at Web.config for class library
Dec 14, 2012 08:36 AM|LINK
At Web.config:
<connectionStrings> <add name="Constr" connectionString="Data Source=.\;Initial Catalog=DatabaseNamet;Integrated Security=True"/> </connectionStrings>Add this namespace using System.Configuration;