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

Error

The following error occurs when Connection property of SqlConnection object is not set or it is invalid.
Server Error in '/.Net' Application.
 
Fill: SelectCommand.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: Fill: SelectCommand.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 Web.Config check the key name is correct or not.
Note: For more details on how to read Connection String from Web.Config file, please refer my article Read or Write Connection Strings in Web.Config file using ASP.Net using C# and VB.Net.
 
3. The variable name should be unique.
 
 

Screenshot

ASP.Net WebForms - Connection property has not been initialized