Solved

there is already an open datareader associated with this command which must be closed first.+vb.net

Posted on 2009-05-16
5
852 Views
Last Modified: 2012-05-07
there is already an open datareader associated with this command which must be closed first.+vb.net
I am closing reader.Close() for each datareaer.
code is working in a single mechine properly.
 more request comes from two or more mechine   then i get an Error
Error-->:there is already an open datareader associated with this command which must be closed first.
Protected Sub BtnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnLogin.Click
 
            Dim sss As String = cn.State.ToString()
            Session("UId") = TBUserName.Text
            Dim ID As String = TBUserName.Text
            cmd = New SqlCommand
            cmd.Connection = cn
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "sp_administration"
            cmd.Parameters.Add("@transid", SqlDbType.Int).Value = 1
            cmd.Parameters.Add("@userid", SqlDbType.VarChar, 50).Value = TBUserName.Text
            cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = TBPassword.Text
 
            rd = cmd.ExecuteReader()  ///Error
          
 
            If rd.Read() Then
                Session("AId") = rd.GetValue(0).ToString()
                Session("CenterId") = rd.GetValue(3)
                Session("CID") = rd.GetValue(3)
                Dim userType As String = rd.GetValue(2).ToString()
                rd.Close()
                Session("UId") = TBUserName.Text
                Session("Utype") = userType.ToString()
                If userType = "0" Then
 
                    Response.Redirect("frmExamDescription.aspx")
                End If
                If userType = "1" Then
 
                    Response.Redirect("frmAdmin.aspx")
                End If
 
                If userType = "2" Then
 
                    Response.Redirect("GeneralExamShedule.aspx")
                End If
            Else
                lblmsg.Text = "Invalid Userid/password"
            End If
            rd.Close()
          
        End Sub
 
 
Connection is openened in a session start event

Open in new window

0
Comment
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
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24402439
Can you post your declaration for the variable "cmd"?
0
 
LVL 7

Accepted Solution

by:
ajolly earned 250 total points
ID: 24402472
Use closed behavior.

rd = cmd.ExecuteReader(CommandBehavior.CloseConnection)
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 250 total points
ID: 24403313
0
 
LVL 6

Expert Comment

by:M3mph15
ID: 24409118
Hi,

You need to close the connection (cn) aswell.
0

Featured Post

Industry Leaders: 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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 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