Solution - There is already an open DataReader associated with this Command which must be closed first.

OleDB Error

There is already an open DataReader associated with this Command which must be closed first.

OleDB Error There is already an open DataReader associated with this Command which must be closed first.
OleDB Error : There is already an open DataReader associated with this Command

Problem

  • There is already an open DataReader associated with this Command which must be closed first.

Cause

  • Having more than 1 dataReader result set working at the same time .

Solution

In my solution example, I work with Sql Server 2000 and VB.Net 2005 
The VB. Net Example Project can be downloaded at the end of this post
It contains (Sql Server 2000 DataBase - VB.Net Project)

The example shows how to :

  • Navigate (First Record - Next Record) using ADO Net 2.0 Online-Mode using SqlClient DataReader ...
  • Sql Database Name : Market
  • Sql Database Table : Market.Info
  • Server Name : evry1falls
  • (in order to see the example correctly, you'll have to Import the Database 'Market' into your sql server 2000 Enterprise Manager)
  • Photo1 : Application Final Design
VB.net SqlServer project
VB .net SqlServer project

Photo2 : Table Structure
vb.net sqlserver datagridview
vb .net sql server 2000 Table

vb.net sqlserver source code
vb .net sql server 2000 Source Code

Photo4 : Codes
vb.net sqlserver source code
vb .net sql server source code

Photo5 : Codes
vb.net sqlserver source code
vb .net sql server source code

Now, if you run the project and tried to navigate using (First) or (Next) you will get the Exception :
There is already an open DataReader associated with this Command which must be closed first .....
So, the solution would be :

Trap the Exception that shows in the (SelectedIndexChanged) Event of the (ComboBox) like this :


And the same for the (Next) Button ..

Now you can Navigate and search using ComboBox Control safely without exceptions ..

Note

  • Source code will give you exception and you will have to re-write the solution by yourself  as shown above .
  • The Folder (Bin/Debug) Includes (Back-Up) use it to restore the (Market Database) in your Sql Server 2000
  • Use the namespace (evry1falls) as new server Registration .

Download Source Code :
MediaFire Link

Using MS Access 2003/2007/2010

In case of using Microsoft Access Database, OleDb.OleDbDataReader with OleDb.OleDbCommand.


The work around or the solution would be :
Always create a new Instance of the OleDbCommand, I.e


Popular posts from this blog

Visual Basic 2010 Working With DataBase Full Project Example

VB NET Check internet connection

VB .NET DropBox Api Source Code Example

VB .NET WebView2 WinForms tips

Visual Basic .Net - Button Sound / Music Play

Visual Basic Online Courses DataGridView Add Edit Delete