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
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.
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
Add System.Configuration Assembly in Project
1. Go to Solution Explorer and Right click on your Project. Select Add and click on Add reference
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;
|
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.
ReplyDeleteSpring 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