I’m going to demonstrate how to get connection string from App.config in C#.Net.
Example
App.config
<?xmlversion="1.0"encoding="utf-8" ?>
<configuration>
<connectionStrings>
<addname="con1"connectionString="Server=abc\SQLEXPRESs;Database=Employee;Trusted_Connection=True"/>
</connectionStrings>
</configuration>
Form1.cs where we are going to use connection string of App.config
//namespace for sqlclient
using System.Data.SqlClient;
//to use connectionstring we have to use System.Configuration namespace
using System.Configuration;
//fetching connectionstring from App.config
string strConnection= ConfigurationManager.ConnectionStrings["con1"].ConnectionString;
//creating newsqlconnection
con= new SqlConnection(strConnection);
//opening connection
con.Open();
Sunil Singh
29-Jun-2017It was really helpful to read this post.