In this article I will explain with an example, how to resolve the error: The ConnectionString property has not been initialized in ASP.Net Core.
 
 

Error

The following error occurs when ConnectionString property of SqlConnection object is not set or it is invalid.
Server Error in '/.Net' Application.
 
The ConnectionString 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 and where it originated in the code.
 
Exception Details:
System.InvalidOperationException: The ConnectionString 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.
Note: For more details on how to read Connection String from AppSettings.json file, please refer my article .Net Core 8: Read Connection String from AppSettings.json file.
 
3. The variable name should be unique.
 
 

Screenshot

ASP.Net Core - The ConnectionString property has not been initialized