Solved

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

Posted on 2009-05-11
1,951 Views
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 62:             cmd.Parameters.Add("@userid", SqlDbType.VarChar, 50).Value = TBUserName.Text
Line 64:             rd = cmd.ExecuteReader()
Line 65:             cmd.Parameters.Clear()
Line 66:             If rd.Read() Then

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

Stack Trace:
0
Question by:logicslab
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

LVL 143

Expert Comment

ID: 24362415
>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

LVL 5

Accepted Solution

aternex earned 500 total points
ID: 25104253
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
###### Suggested Courses
Course of the Month7 days, 11 hours left to enroll

#### 632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.