Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on n-tier application with separate BLL and DAL classlibraries. I have connectionstring in web.config file. And in UI i can access it but how to access in BLL and DAL. In User Interface i have two classes one which i made connectionClass as public shared function GetConnStr() as string and function return connstring thru configMgr and in other class as baseClass for connection i have two constructor call with constr as parameter and without. And property for connectionstring.
Now i can access connstr in UL but i can't access it if i am writing same baseClass in BLL and DAL. I feel I short of some step to access connstring. I have error saying "constr is not intialized"

Another problem is in property page of UI i used imported Namespaces to import connectionClass but it seems not working. How to know it is working plz help.

I would appreciate to get correct methods for coding and nice way of asking question if I am not so expressive. Plz pardon me if I am overexpressive. I am new to codeproject and new to .net. I got learning inspirsation for your website.
Thank You
Posted

you can access
sample code like
C#
string strCon = "";           
strCon = System.Configuration.ConfigurationManager.AppSettings.Get("ConString");
Include using System.Configuration; in the class
 
Share this answer
 
All libraries in the AppDomain have access to the web.config data through the ConfigurationManager class (using System.Configuration)

So in a class library,
string connString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;


Use this way in order to access the connection string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900