top of page

The ConnectionString property has not been initialized

  • Writer: Alex Vincy
    Alex Vincy
  • Aug 26, 2018
  • 1 min read

Question

I am getting "The connection string property has not been initialized" while connecting to my SQL server database.

web.config

<configuration>
  <appSettings>
    
  </appSettings>
</configuration>

C# Code behind

SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationSettings.AppSettings["sql_con"];

Answer

Modify the code behind as below, and don't forget to add the System.Configuration namespace

SqlConnection conn = new SqlConnection(); 
conn.ConnectionString = ConfigurationManager.ConnectionStrings["sql_con

Comments


© 2023 by Money Savvy. Proudly created with wix.com

Get Social

  • Grey Facebook Icon
  • Grey Twitter Icon
  • Grey Google+ Icon
  • Grey LinkedIn Icon
  • Grey YouTube Icon
bottom of page