Example 1 : In appSettings section in web.config
Web.Config
In .cs file , Configuration Manager class is used to fetch connection string . See below code to see how :
string strSQLConnection1 = ConfigurationManager.AppSettings["SQLConnection1"];
But the better way is to add connection string in connectionstrings tag in web.config
See Web.Config for details :
You can retrieve the connection string in web.config using Configuration Manager class in .cs file :
string strSQLConnection2 = ConfigurationManager.ConnectionStrings["SQLConnection2"].ConnectionString;
No comments:
Post a Comment