Solved

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

Posted on 2009-05-16
5
850 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 70

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

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Run 3 sliders vertically as opposed to horizontally 9 21
Entity Framework 7 41
Message not shown 5 49
How to make a GridView cell hyperlinked using C# ? 3 33
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

815 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

8 Experts available now in Live!

Get 1:1 Help Now