Server Error in 'Performance' 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 and where it originated in the code.

Exception Details: System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.

Function FncReadQuery(ByVal StrSql As String, ByVal DT As String) As OleDb.OleDbCommand
            Dim ConnNewClient As New OleDb.OleDbConnection()
            Dim commNewClient As New OleDb.OleDbCommand
            Dim DbPath As String = FncGetPath()

            ConnNewClient = New OleDbConnection
            ConnNewClient = FncDBConnect(DbPath)
            commNewClient = New OleDbCommand
            commNewClient.CommandTimeout = 3600
            commNewClient.Connection = ConnNewClient
            commNewClient.CommandText = StrSql

            With commNewClient.ExecuteReader
                If .HasRows Then
                    ConnNewClient.Close()
                    Return commNewClient
                Else
                    commNewClient = Nothing
                    Return Nothing
                End If
            End With
            ConnNewClient.Close()
            ConnNewClient = Nothing
            commNewClient = Nothing
        End Function

I'll assume that

ConnNewClient = FncDBConnect(DbPath)

sets the connection string, although I have no reason to do so. Before you access the database you must open the connection like

ConnNewClient.Open()

If FncDBConnect already opened the connection then that is not the problem. You didn't include that code so there is no way to say for sure.

Edited 1 Year Ago by Reverend Jim

FncDBConnect already opened the connection and i think the cause of error is right here

With commNewClient.ExecuteReader

Edited 1 Year Ago by Diomarch

The error says "ExecuteReader: Connection property has not been initialized". The obvious thing to check would be your connection string and the code that opens the connection, but, as I pointed out, you didn't post that code.

Edited 1 Year Ago by Reverend Jim

This article has been dead for over six months. Start a new discussion instead.