0

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
2
Contributors
5
Replies
38
Views
2 Years
Discussion Span
Last Post by Reverend Jim
0

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 by Reverend Jim

0

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

With commNewClient.ExecuteReader

Edited by Diomarch

0

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 by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.