aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Get (Read) Connectionstring from App.Config File in C#, VB.Net

Feb 26, 2015

Here I will explain how to read or get connectionstring from app.config file in
c#, By using System.Configuration reference we can read or get connectionstring from app.config file in windows or console application in c#,


In previous post I explained encrypt or decrypt connectionstring in app.config file, export datagridview to crystal report in windows application,
convert currency or numbers to words in, angularjs bind dropdownlist with text and value, jQuery tag cloud example in and many more articles related to using c#, Now I will explain how to read or get connectionstring from app.config file in c#,

To read connectionstring from app.config file first create new windows application and open your app.config file and add conneciton string like as shown below

<add name="dbconnection" connectionString="DataSource=Suresh;Initial Catalog=Praveendb;Integrated Security=true" providerName="System.Data.SqlClient" />

To read this connectionstring in our windows or console application we need to add System.Configuration reference for that follow below steps

Right click on your References folder à select Add Reference à select .NET tab à in that select System.Configuration à Click OK like as shown below

Get (Read) Connectionstring from App.Config File in C#, VB.Net

After completion of adding reference add following namespaces in codebehind

C# Code

using System.Configuration;


Imports System.Configuration;

After completion of adding namespaces you need to write the code like as shown below to get connectionstring from app.config file

C# Code

string strcon = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;


Dim strcon As String = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;

I hope it helps you to read connectionstring from app.config file…. Happy coding…

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.