Read Connection String from Web.Config file in ASP.Net using C# and VB.Net

Read Connection String from Web.Config file in ASP.Net using C# and VB.Net

Today, We want to share with you Read Connection String from Web.Config file in ASP.Net using C# and VB.Net.In this post we will show you c# – Read connection string from web.config, hear for Get ConnectionString From Web.Config File ASP.Net we will give you demo and example for implement.In this post, we will learn about How To Read And Write Connection String In Web.Config? with an example.

Read Also:  SQL SELECT SUM on multiple INNER JOIN with another table

In this post, we will learn about how to Read Connection String from Web.Config file in ASP.Net using C# and VB.Net with an example.

Now in this post, I will explain how to Read Connection String from Web.Config file in ASP.Net using C# and VB.Net with appropriate example. In ASP.Net Web applications, it requires reference to the System.Configuration Assembly in order to read Connection String value from the Web.Config file.

Read Also:  jQuery Validate Email address using Regex Expression

C# VB.Net Read Connection String from Web.Config file in ASP.Net

First, you need to add the Connection String in the ConnectionStrings section of the Web.Config file in the following way.

<configuration>
    <connectionStrings>
        <add name="ConString" connectionString="Data Source=DotNetK-PC\SQL2005;Initial Catalog=Northwind;Integrated Security=true" />
    </connectionStrings>
</configuration>

Now,you can read the Connection String value by its name from the Web.Config file in the following way.

Get Dynamically connection string in app.config file c#

C# :

string connectionStr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;

VB.Net :

Dim connectionStr As String = ConfigurationManager.ConnectionStrings("ConString").ConnectionString

Read :

Read Also:  how to check username and password from database in asp.net using c#

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about C# VB.Net Read Connection String from Web.Config file in ASP.Net.I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  react open new tab with url Example Tutorial
  2. Read Also:  VueJs Dynamic Class and Style Bindings
  3. Read Also:  How to return view with flash message in Laravel 6?
  4. Read Also:  Laravel 6 Get Last Inserted ID using Eloquent
  5. Read Also:  Laravel 6 Image Uploader and Browser for CKEditor
  6. Read Also:  Laravel Passing Multiple Variables from Controller to View
  7. Read Also:  PHP Laravel 5.8 Image Uploading Tutorial
  8. Read Also:  Laravel Passing Multiple Variables from Controller to View
  9. Read Also:  jQuery Validate Email address using Regex Expression
  10. Read Also:  Laravel 6 Image Uploader and Browser for CKEditor
CLOSEX