Hi,
I ran the same code with two different providers (oledb abd sqlclient), and
i got two different behaviours.
The code with OLEDB runs perfect without error.
The same code with SQLClient gives an error at line: "dtreader =
comd.ExecuteReader" (the second)
"There is already an open DataReader associated with this Command which must
be closed first."
Why must the DataReader be closed with provider SqlClient and not with
Oledb?
Any explanation for that?
Thanks
Bart
1) with OleDb:
-------------
Imports System.Data.OleDb
Partial Class studalres
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim oConnection As OleDbConnection
Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader
Dim sql As String
oConnection = New OleDbConnection()
oConnection.ConnectionString =
System.Configuration.ConfigurationManager.Connecti onStrings("oledbdemo").ToString()
oConnection.Open()
sql = "SELECT pc.naam FROM pc ;"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
'dtreader.Close()
sql = "SELECT pc.naam FROM pc ;"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
dtreader.Close()
oConnection.Close()
End Sub
End Class
2) with SqlClient :
----------------
Imports System.Data
Imports System.Data.sqlclient
Partial Class studalres
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim oConnection As SqlConnection
Dim comd As SqlCommand
Dim dtreader As SqlDataReader
Dim sql As String
oConnection = New SqlConnection()
oConnection.ConnectionString =
System.Configuration.ConfigurationManager.Connecti onStrings("sqlclientdemo").ToString()
oConnection.Open()
sql = "SELECT pc.naam FROM pc ;"
comd = New SqlCommand(sql, oConnection)
dtreader = comd.ExecuteReader
'dtreader.Close()
sql = "SELECT pc.naam FROM pc ;"
comd = New SqlCommand(sql, oConnection)
dtreader = comd.ExecuteReader
'here is the error
dtreader.Close()
oConnection.Close()
End Sub
End Class 2 1085
Each reader needs a connection, and the provider may either open a new
connection in the background or refuse to run the query. This can be
controlled from a setting in the connection string, and the default
value of this setting is obviously different for these providers.
Bart wrote:
Hi,
I ran the same code with two different providers (oledb abd sqlclient), and
i got two different behaviours.
The code with OLEDB runs perfect without error.
The same code with SQLClient gives an error at line: "dtreader =
comd.ExecuteReader" (the second)
"There is already an open DataReader associated with this Command which must
be closed first."
Why must the DataReader be closed with provider SqlClient and not with
Oledb?
Any explanation for that?
Thanks
Bart
1) with OleDb:
-------------
Imports System.Data.OleDb
Partial Class studalres
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim oConnection As OleDbConnection
Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader
Dim sql As String
oConnection = New OleDbConnection()
oConnection.ConnectionString =
System.Configuration.ConfigurationManager.Connecti onStrings("oledbdemo").ToString()
oConnection.Open()
sql = "SELECT pc.naam FROM pc ;"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
'dtreader.Close()
sql = "SELECT pc.naam FROM pc ;"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
dtreader.Close()
oConnection.Close()
End Sub
End Class
2) with SqlClient :
----------------
Imports System.Data
Imports System.Data.sqlclient
Partial Class studalres
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim oConnection As SqlConnection
Dim comd As SqlCommand
Dim dtreader As SqlDataReader
Dim sql As String
oConnection = New SqlConnection()
oConnection.ConnectionString =
System.Configuration.ConfigurationManager.Connecti onStrings("sqlclientdemo").ToString()
oConnection.Open()
sql = "SELECT pc.naam FROM pc ;"
comd = New SqlCommand(sql, oConnection)
dtreader = comd.ExecuteReader
'dtreader.Close()
sql = "SELECT pc.naam FROM pc ;"
comd = New SqlCommand(sql, oConnection)
dtreader = comd.ExecuteReader
'here is the error
dtreader.Close()
oConnection.Close()
End Sub
End Class
--
Göran Andersson
_____ http://www.guffa.com
Thanks
"Göran Andersson" <gu***@guffa.comschreef in bericht
news:OU**************@TK2MSFTNGP06.phx.gbl...
Each reader needs a connection, and the provider may either open a new
connection in the background or refuse to run the query. This can be
controlled from a setting in the connection string, and the default value
of this setting is obviously different for these providers.
Bart wrote:
>Hi,
I ran the same code with two different providers (oledb abd sqlclient), and i got two different behaviours. The code with OLEDB runs perfect without error. The same code with SQLClient gives an error at line: "dtreader = comd.ExecuteReader" (the second) "There is already an open DataReader associated with this Command which must be closed first."
Why must the DataReader be closed with provider SqlClient and not with Oledb? Any explanation for that?
Thanks Bart
1) with OleDb: ------------- Imports System.Data.OleDb Partial Class studalres Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim oConnection As OleDbConnection Dim comd As OleDbCommand Dim dtreader As OleDbDataReader Dim sql As String
oConnection = New OleDbConnection() oConnection.ConnectionString = System.Configuration.ConfigurationManager.Connect ionStrings("oledbdemo").ToString() oConnection.Open()
sql = "SELECT pc.naam FROM pc ;" comd = New OleDbCommand(sql, oConnection) dtreader = comd.ExecuteReader 'dtreader.Close()
sql = "SELECT pc.naam FROM pc ;" comd = New OleDbCommand(sql, oConnection) dtreader = comd.ExecuteReader dtreader.Close() oConnection.Close() End Sub End Class
2) with SqlClient : ---------------- Imports System.Data Imports System.Data.sqlclient Partial Class studalres Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim oConnection As SqlConnection Dim comd As SqlCommand Dim dtreader As SqlDataReader Dim sql As String
oConnection = New SqlConnection() oConnection.ConnectionString = System.Configuration.ConfigurationManager.Connect ionStrings("sqlclientdemo").ToString() oConnection.Open()
sql = "SELECT pc.naam FROM pc ;" comd = New SqlCommand(sql, oConnection) dtreader = comd.ExecuteReader 'dtreader.Close()
sql = "SELECT pc.naam FROM pc ;" comd = New SqlCommand(sql, oConnection) dtreader = comd.ExecuteReader 'here is the error dtreader.Close() oConnection.Close() End Sub End Class
--
Göran Andersson
_____ http://www.guffa.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Viviana Vc |
last post by:
Hi all,
I am using Win2k, VS. NET 7.1 (MS development Environment 2003 7.1.3088)
and I noticed that by building the exact same code twice the generated
binaries are different (not much, but they...
|
by: emaileric |
last post by:
Hi all, I am looking for a way to create two different forms, with
different look and feel. However, they would both have the same set of
controls, and reference the same code behind page. I...
|
by: iwdu15 |
last post by:
hi, i have these 2 code snippets:
Public Sub ImRec(ByVal IM As IAccIm, ByVal Sender As IAccUser)
Dim str As String = IM.GetConvertedText(DECODE)
Dim temp As String = str
temp =...
|
by: yalebulldog05 |
last post by:
Watsup everyone,
I'm having 2 problems, both dealing with similar themes of having code work for all possible series/worksheets, so i'm wondering if there's a macro that deals with this:
1) I'd...
|
by: Bart |
last post by:
Hi,
I ran the same code with two different providers (oledb abd sqlclient), and
i got two different behaviours.
The code with OLEDB runs perfect without error.
The same code with SQLClient...
|
by: rathour |
last post by:
<?php
session_start();
require_once('db.php');
include('functions.php');
$user = get_username ( $_SESSION );
//if ( $_SESSION ):
checkLogin ( '1 2' );
?>
|
by: ashjas |
last post by:
Hello,
though this code uses opengl library freeglut,the problem seems to be c++ related..kindly help. and all coding is done in c++
when i try to execute the code,i get this error
freeglut ...
|
by: Christopher Brewster |
last post by:
I am running the same script on the same data on two different
machines (the folder is synchronised with Dropbox).
I get two different results. All the script does is count words in
different...
|
by: sganeshsvk |
last post by:
sir,
i want to store the same data values in two different databases at that same time in mysql using php programming.
suppose any one databases data will lose then we use the other...
|
by: Aj Singh |
last post by:
I have mulitple websites using the same code but different web.config files. Is there a way where I can achieve not having multiple copies of the same code? so its easy to mantain?
Thanks
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| | |