0
<connectionStrings>
  <add name="mycollegeproject" connectionString="Data Source=mssql2.gear.host;Initial Catalog=mycollegeproject;Persist Security Info=True;User ID=mycollegeproject;Password=*******" />
</connectionStrings>

public static string strcon = ConfigurationManager.ConnectionStrings["mycollegeproject"].ConnectionString;

And the error

System.NullReferenceException: Object reference not set to an instance of an object.
Rahul
  • 71,392
  • 13
  • 57
  • 105

1 Answers1

0

If not wrong, mostly you have no connection string defined in your App.config named mycollegeproject (OR) you are using a different key name in your code rather than using mycollegeproject and so the below code line returns NULL resulting in NRE.

ConfigurationManager.ConnectionStrings["mycollegeproject"]
Rahul
  • 71,392
  • 13
  • 57
  • 105