I am trying to call a connection string from app.config file in 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 get a Null Reference Exception and when debugging a program, connStudent is always null and does not get a connection string. Error: "The object reference is not installed on the object instance."
c # xml app-config
user919789
source share