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
                    Return commNewClient
                    commNewClient = Nothing
                    Return Nothing
                End If
            End With
            ConnNewClient = Nothing
            commNewClient = Nothing
        End Function

Recommended Answers

All 5 Replies

You didn't open the connection.

how can you give me a sample?

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


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.

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

With commNewClient.ExecuteReader

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.