473,960 Members | 4,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InvalidOperatio nException: There is already an open DataReader ass

Hi,

I keep getting the following error message:

InvalidOperatio nException: There is already an open DataReader associated
with this Connection which must be closed first.

I have read up about it and realise that you can only have one DataReader
open on a Connection at a time, but don't know how to rewrite my code to work
properly.

Currently I have the following:
Protected Shared myDA As SqlDataAdapter

Protected Shared ReadOnly Property DataAdapter() As SqlDataAdapter
Get
If myDA Is Nothing Then
myDA = New SqlDataAdapter( "SELECT * FROM Course",
CData.Connectio n)
Dim cb As New SqlCommandBuild er(myDA)
myDA.UpdateComm and = cb.GetUpdateCom mand()
myDA.InsertComm and = cb.GetInsertCom mand()
myDA.DeleteComm and = cb.GetDeleteCom mand()
CData.Connectio n.Close()
End If
Return myDA
End Get
End Property
Public Shared Function GetCourse(ByVal CourseID As Integer) As CCourse
Dim selectText As String = DataAdapter.Sel ectCommand.Comm andText
DataAdapter.Sel ectCommand.Comm andText = "SELECT * FROM Course WHERE
CourseID =" & CourseID
Dim dt As New DataTable
DataAdapter.Fil l(dt)
DataAdapter.Sel ectCommand.Comm andText = selectText
If dt.Rows.Count = 0 Then
Return Nothing
Else
Return New CCourse(dt.Rows (0))
End If
End Function
When I try to access the GetCourse Function from two different computers at
the same time it gives the error as mentioned above.

Can anyone help me to solve this problem... i.e. am I writing my code
completely wrong.

Any help would be much appreciated.

Thanks in advance.

Grant.
Nov 19 '05 #1
2 2872
Sorry, forgot to put that I am using .Net 1.1 with service pack 2, and
connecting to SQL Server 2005.

Thanks.

"Grant" wrote:
Hi,

I keep getting the following error message:

InvalidOperatio nException: There is already an open DataReader associated
with this Connection which must be closed first.

I have read up about it and realise that you can only have one DataReader
open on a Connection at a time, but don't know how to rewrite my code to work
properly.

Currently I have the following:
Protected Shared myDA As SqlDataAdapter

Protected Shared ReadOnly Property DataAdapter() As SqlDataAdapter
Get
If myDA Is Nothing Then
myDA = New SqlDataAdapter( "SELECT * FROM Course",
CData.Connectio n)
Dim cb As New SqlCommandBuild er(myDA)
myDA.UpdateComm and = cb.GetUpdateCom mand()
myDA.InsertComm and = cb.GetInsertCom mand()
myDA.DeleteComm and = cb.GetDeleteCom mand()
CData.Connectio n.Close()
End If
Return myDA
End Get
End Property
Public Shared Function GetCourse(ByVal CourseID As Integer) As CCourse
Dim selectText As String = DataAdapter.Sel ectCommand.Comm andText
DataAdapter.Sel ectCommand.Comm andText = "SELECT * FROM Course WHERE
CourseID =" & CourseID
Dim dt As New DataTable
DataAdapter.Fil l(dt)
DataAdapter.Sel ectCommand.Comm andText = selectText
If dt.Rows.Count = 0 Then
Return Nothing
Else
Return New CCourse(dt.Rows (0))
End If
End Function
When I try to access the GetCourse Function from two different computers at
the same time it gives the error as mentioned above.

Can anyone help me to solve this problem... i.e. am I writing my code
completely wrong.

Any help would be much appreciated.

Thanks in advance.

Grant.

Nov 19 '05 #2
Helo we have the same problem wth our application. We use .net 1.1 and sql 2005. Code works fine with one user working on it but if two or more users start to access the code with DataReader from two different computers at the same time it gives the error "There is already an open DataReader associated
with this Connection which must be closed first.". We are 1005 sure we close our reader and connection properly.

Have you managed to resolve this problem since your post?
Joanna
From http://www.developmentnow.com/g/8_20...Reader-ass.htm

Posted via DevelopmentNow. com Groups
http://www.developmentnow.com
Sep 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1429
by: jason | last post by:
Hi, {asp .net 1.1, sp 2) I am facing problems with multi users accessing the same page. There is a datagrid in the webform. The "datareader already opened error/ object reference not found" errors will occur randomly when multi users are clicking page number (paging), any page number. The connection object is declared private and connection is closed
2
3188
by: rn5a | last post by:
The following code resides in a VB class file name GetOrder.vb (this class file exists in the App_Code directory): Namespace Shop Public Class Orders Public Function ViewOrder(ByVal UserID As Integer, ByVal OrderID As Integer) As SqlDataAdapter Dim sqlDapter As SqlDataAdapter Dim sqlConn As SqlConnection
20
7237
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I get the error "There is already an open DataReader associated with this Connection which must be closed first." How can I fix this error ? For each DataReader, do I want to open and close the connection (in this case adoCon) to avoid this error ?...
10
6130
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the code below which when executed generates the following error message: 'There is already an open datareader with this command which must be closed first' Private Sub MainMenu_Load(ByVal sender As System.Object, ByVal e As
13
3431
by: Bart | last post by:
Hi, i get the error: "There is already an open DataReader associated with this Command which must be closed first" Thanks Bart ----------------------------------------- Imports System.Data.sqlclient
3
13210
by: BLUE | last post by:
I've a TransactionScope in which I select some data and I want to do some queries for each record retrieved with my select. I'm using a DataReader and for each record I do factory.CreateCommand() and then I execute the command, but I get the following exception message: " There is already an open DataReader associated with this Command which must be closed first. " Searching on google I've found I've to create another connection, but...
0
10269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11479
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10807
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8382
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7537
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6315
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6457
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.