Solved

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

Posted on 2009-05-16
5
849 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
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 69

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

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

15 Experts available now in Live!

Get 1:1 Help Now