The ConnectionString property has not been initialized
- 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