-->

23 February 2020

asp.net Web.config connectionStrings

  Asp.Net CS By Example       23 February 2020

 Setting Static Variables Using the <connectionStrings> Tag 

 In this post, we shall learn on how to connection String from Web.Config file in Asp.Net.The <connectionStrings> tag supports only two attributes, a name and a connectionString.This setting enables We to set different static database connection string for our application. One excellent use for this configuration setting is to set all of our application specific database connection string in a single location.This gives we the ability to completely control our application through a single configuration file.The following code shows the use of this tag in setting a data source name for our web application.

web.config
 <?xml version="1.0"?>
 <configuration>
 <connectionStrings  >
  < add  name="LearnAsp" connectionString="data source=LearnAsp;user id=LearnAsp; 
  password=LearnAsp; Pooling=true; Max pool size=20; Min pool size=0;"/> 
 </connectionStrings>
 </configuration>
        

 To retrieve configuration data from Web.config, we use the ConfigurationManager class, which is located in the System.Configuration namespace.

string strConn = 
            ConfigurationManager.ConnectionStrings["LearnAsp"].ToString(); 
logoblog

Thanks for reading asp.net Web.config connectionStrings

Previous
« Prev Post

No comments:

Post a Comment

Please do not enter any spam link in the comment box.