there is already an open datareader associated with this command which must be closed

Posted on 2009-05-16
Last Modified: 2012-05-07
there is already an open datareader associated with this command which must be closed
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()


                Session("UId") = TBUserName.Text

                Session("Utype") = userType.ToString()

                If userType = "0" Then


                End If

                If userType = "1" Then


                End If

                If userType = "2" Then


                End If


                lblmsg.Text = "Invalid Userid/password"

            End If



        End Sub

Connection is openened in a session start event

Open in new window

Question by:logicslab
LVL 75

Expert Comment

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

Accepted Solution

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

rd = cmd.ExecuteReader(CommandBehavior.CloseConnection)
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 250 total points
ID: 24403313

Expert Comment

ID: 24409118

You need to close the connection (cn) aswell.

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 ( First, just open a new email message. In the To field, type your recipient's fax number 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