I'm trying to call a connection string from the app.config file to C# code. This is the app.config code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="connectstring" value="Data Source=server111;Initial Catalog=database1; Integrated Security=False;Persist Security Info=False; User ID=username;Password=password;Encrypt=True; TrustServerCertificate=True; MultipleActiveResultSets=True"/>
</appSettings>
</configuration>
This is the C# code:
private SqlConnection connStudent;
connStudent = new SqlConnection(ConfigurationManager.AppSettings["connectstring"].ToString());
connStudent.Open();
The code should be right, but I'm getting a Null Reference Exception, and while debugging the program, connStudent is always null and does not get the connection string . The error is "Object reference not set to an instance of an object".