Solved

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

Posted on 2009-05-16
5
847 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 74

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

13 Experts available now in Live!

Get 1:1 Help Now