How To Setup Connection String In ASP.NET To SQL SERVER




Here we consider how to setup connection string to SQL Server in Asp.Net. First of all navigate to Views --> Server Explorer on Visual Studio. Right Click on Data Connections --> Add Connection. A new window will come as shown below. Here provide Server Details. Provide Server Name, Log On Information, Database Name.

How To Setup Connection String In ASP NET To SQL SERVER, Setup Connection String In ASP NET To SQL SERVER, Setup Connection String In ASP NET, Connection String In C#, Setup Connection String, Connection String, Connection String To SQL SERVER, SQL SERVER, Entity Framework

And then press OK Button. This newly added database will be listed under Data Connection in Server Explorer. Right Click on this Database Connection and Select Properties. On Properties Window, Copy Connection String as shown below.

How To Setup Connection String In ASP NET To SQL SERVER, Setup Connection String In ASP NET To SQL SERVER, Setup Connection String In ASP NET, Connection String In C#, Setup Connection String, Connection String, Connection String To SQL SERVER, SQL SERVER, Entity Framework

On Web.Config file, inside configuration Section, add ConnectionString node as shown below.

<connectionStrings >
    <add
         name="conString" 
         connectionString="Paste Your Connection String Here"
         providerName="System.Data.SqlClient"/>
</connectionStrings>



Inside connectionStrings node, paste your Connection String inside connectionStrings="".
On code behind, you can set up connection variable as shown below.

SqlConnection connectionString = new SqlConnection(
WebConfigurationManager.ConnectionStrings["conString"].ConnectionString);



That's all, now you can make use of connectionString Variable for further database operation.