Solved

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

Posted on 2009-05-11
2
1,923 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 143

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

735 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