Here I will explain How to retrieve Connection String from Web.config in Class.cs file when using Three Tire Architecture or More Tires. Here in 3 tire...
- UI Validation (ASP.Net) //ASP.Net web application
- BLL (Business Logic Layer) //Windows - Class Library project
- DAL (Data Access Layer) //Windows - Class Library project
Here we had
TWO ways to get connection string from we.config file.
- In 1st method we can get connection string in web.config file from
<connectionStrings/> tag i.e.,
<connectionStrings>
<add name="constring"
connectionString="server=(local)\SQLEXPRESS;
database=sampleDB;
user id=sa;
pwd=*********;" />
</connectionStrings>
and now we need to add reference
System.Configuration.dll
and the connection string can be written as shown below
private string constring =
ConfigurationManager.ConnectionStrings["constring"].ToString();
For ThreeTite architecture Click
HERE
No comments:
Post a Comment