473,857 Members | 1,842 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 2867
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
1427
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
3185
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
7224
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
6118
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
3423
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
13202
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
9923
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
9768
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10711
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
10808
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
10394
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
7940
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
5971
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.