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#     1 comment   


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 TwitterShare to Facebook
Newer Post Older Post Home

1 comment:

  1. for ict 9931 July 2020 at 22:25

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Projects for CSE It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai


    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete
    Replies
      Reply
Add comment
Load more...

Facebook Updates

Guruji Point

Categories

comma seperated string in sql Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS row_number() and dense_rank() salary table structure. Scope_Identity() Use of indexes 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