Link to home
Start Free TrialLog in
Avatar of logicslab
logicslab

asked on

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

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

Avatar of kaufmed
kaufmed
Flag of United States of America image

Can you post your declaration for the variable "cmd"?
ASKER CERTIFIED SOLUTION
Avatar of ajolly
ajolly
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

You need to close the connection (cn) aswell.