• Status: Solved
• Priority: Medium
• Security: Public
• Views: 2171

# ExecuteReader requires an open and available Connection. The connection's current state is connecting.

Server Error in '/' Application.
--------------------------------------------------------------------------------

ExecuteReader requires an open and available Connection. The connection's current state is connecting.
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 requires an open and available Connection. The connection's current state is connecting.

Source Error:

Line 65:             cmd.Parameters.Clear()

Source File: F:\hshome\hello5\testmylogic.com\default.aspx.vb    Line: 64

Stack Trace:
0
logicslab
1 Solution

Billing EngineerCommented:
>Exception Details: System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is connecting.

the error message tells you that you did not assign a connection object to the command, resp that the connection is not open.
the problem is in the code above what you posted.
0

Commented:
Try something like below, this will assign the connection to the command object and open it.

Using oConn As New SqlConnection(connectionString)
Using oCmd As New SqlCommand()
With oCmd
.Connection = oConn
.CommandType = CommandType.StoredProcedure
.CommandText = "storedProcedureName"
.Parameters.Clear()
.Connection.Open()
End With

If oRs.HasRows() Then
' Do whatever you need with the reader here.
End If

oRs.Close()
End Using
End Using
End Using

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.