Solved

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

Posted on 2009-05-11
2
1,870 Views
Last Modified: 2012-05-06
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 63:             cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = TBPassword.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
Comment
Question by:logicslab
2 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
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

by:
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()

      .Parameters.AddWithValue("@userid", TBUserName.Text)

      .Parameters.AddWithValue("@password", TBPassword.Text)

      .Connection.Open()

    End With
 

    Using oRs As SqlDataReader = oCmd.ExecuteReader(CommandBehavior.CloseConnection)

      If oRs.HasRows() Then

        ' Do whatever you need with the reader here.

      End If
 

      oRs.Close()

    End Using

  End Using

End Using

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating a flowchart from an algorithm 5 30
Code works but how can I download the file? 20 67
What .NET website keeps me current? 9 54
Data is not showing from images 15 37
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now