Home > DeveloperSection > Articles > Connection String using App.config

Connection String using App.config

1 Comment(s)
 16304  View(s)
Rate this:

Connection string using App.config in .NET

I’m going to demonstrate how to get connection string from App.config in C#.Net.



<?xmlversion="1.0"encoding="utf-8" ?>






Form1.cs where we are going to use connection string of App.config

//namespace for sql client

using System.Data.SqlClient;

//to use connection string we have to use System.Configuration namespace

using System.Configuration;


//fetching connection string from App.config

string strConnection = ConfigurationManager.ConnectionStrings["con1"].ConnectionString;

//creating new sqlconnection

            con = new SqlConnection(strConnection);

//opening connection



By Sunil Singh on   one month ago

It was really helpful to read this post.

Don't want to miss updates? Please click the below button!

Follow MindStick