Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Saturday, 24 June 2017

Write ConnectionString In C# Asp.Net Web.Config

 asp.net, C#     No comments   


Introduction
In this article we will learn How to write connectionstring in C#. ConnectionString in Asp.Net. Why do we need ConnectionString  in C#. Write connection string in Web.Config file. Read connectionstring from Web.config.

Previous Updates
In previous articles we have learnt EncryptByPassPhrase and DecryptByPassphrase  function in Sql  Base64 Encoding And Decoding In SQL Server. Transform multiple rows into one comma separated string column. What is Cursor in sql and use of cursor. AngularJS basics.

Description
You can write your connectionstring in Web.Config file or also in every page where you need the database connection. But by writing this on web.config file you don't need to write this in every page. You just reference the ConnectionString name in every page where you need it.

ConnectionString In Web.Config


<connectionStrings>
      <add name="ConStr" connectionString="Data Source=guruji-PC;Initial Catalog=EmpDetail;Integrated Security=True"/>
    </connectionStrings>

In this Connection String -
Data-Source - Sql Server Instance Name.
Initial Catalog - Your Database Name
Integrated Security - By default its false. If we did not use the Sql Server authentication (UserName and Password) then we give this true.


For use the ConnectionString in Asp.Net Web Application C# code page we need to reference the System.Configuration Assembly in or application.

Add System.Configuration Assembly in Project 

1. Go to Solution Explorer and Right click on your Project. Select Add and click on Add reference

Note- you will find this step in VS13 nd 15. If you are using VisualStudio 2010 or 12 then by right clicking you can directly seen Add reference option.

2. A new Popup window will open and search for System.Configuration and add this assembly by clicking on checkbox just front of its name. And click on OK.

You successfully Add a System.Configuration assembly reference.

Read the ConnectionString From Web.Config

On your .Cs page file you can use the web.config global connection string by using the below code

string connectionString = 
ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write