In this article I will explain with an example, how to resolve the error:
The Connection property has not been initialized in
ASP.Net Core.
Error
The following error occurs when Connection property of SqlConnection object is not set or it is invalid.
Server Error in '/.Net' Application.
ExecuteReader: Connection property has not been initialized.
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error andwhere it originated in the code.
Exception Details:System.InvalidOperationException: ExecuteReader:Connection property has not been initialized.
Solution
The solution to this problem is to make sure following things are correct:
1. Check if you are assigning value to SqlConnection object or not.
2. If connection string is coming from
AppSettings.json check the key name is correct or not.
3. The variable name should be unique.
Screenshot