ASP.NET - Accessing connection string from web.config



Access Connection String from code behind

 
using System.Configuration; // Configuration Manager
  //Accessing connection Sting as usual if encrypted too
 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlCon"].ConnectionString);

Storing Connection String in web.config

 
<configuration>
<appSettings />
  <connectionStrings>
    <add name="SqlCon" connectionString="Server=syntaxhelp; Database=syntaxhelp; User ID=sa; password= hima; "
      providerName="System.Data.SqlClient" />
  </connectionStrings>

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.