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
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
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 70

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

688 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