Live Chat Icon For mobile
Live Chat Icon

Why do I get the error message ‘ExecuteReader: Connection property has not been initialized’

Platform: ASP.NET| Category: ADO.NET

This error is caused if there is no Connection object associated with the Command Object.
To resolve this

VB.NET


Dim cn as new SqlConnection('<your connection string>')
’Dim cn as new OleDbConnection('<your connection string>')
Dim cmd As new SqlCommand('Select * from Products', cn)
’Dim cmd As new OleDbCommand('Select * from Products', cn)

C#


SqlConnection  cn = new SqlConnection ('<your connection string>');
’OleDbConnection cn = new OleDbConnection ('<your connection string>');
SqlCommand cmd = new SqlCommand ('Select * from Products', cn);
’OleDbCommand cmd = new OleDbCommand ('Select * from Products', cn);

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.