Get ConnectionString From Web.Config File ASP.Net

Get ConnectionString From Web.Config File ASP.Net

In this asp.net post i will explain you how to get or read connectionstring from web.config file in asp.net using c# and vb.net.

We can write out connectionstring string in web.config file as following two ways..

1. Write connectionstring inside  <ConnectionString> </ConnectionString>  tag.
2. Write conectionstring inside <appSettings></appSettings> tag

First way to write connectionstrin inside <ConnectionString> tag in we.config:

Write connectionstring inside ConnectionString tag inWeb.Config file.

We can read conectionstring from web.config file using System.Configuration. First imports System.Configuration namespace for read connectionstring from web.config file.

Read ConnectionString using C# from web.config.

 Read ConnectionString using VB.Net from web.config.

Now. let’s understand second way to read connectionstring from web.config file.

Write connectionstring inside appSettings tag inWeb.Config file.

Read ConnectionString using C# from web.config.

 Read ConnectionString using VB.Net from web.config.

Leave a Reply

Your email address will not be published. Required fields are marked *

9 + 1 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">