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 *

3 × four =