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. 2 2865
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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
|
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 ?...
|
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
|
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
| |
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...
|
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...
|
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,...
|
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...
|
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |