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 1249
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: Dave |
last post by:
Hi,
I tried something with 'return value' of a function and i got two different
behaviours.
My question is: why does method 1 not work?
Thanks
Dave
method 1: here, whatever i choose (ok or...
|
by: Chuck |
last post by:
I appreciate any help!!!
I have an application that has 4 different forms that display the same
information except for the fact that they are fed from 4 different
parameter queries. The 4...
|
by: Karlo Lozovina |
last post by:
Hi everyone!
One quick question, with hope that the answers will be the same :). What
to use if I want to ship two versions of my application, one using SQLite,
small embedded database for...
|
by: Michael Primeaux |
last post by:
Why does the generic SortedList and generic SortedDictionary not define any
virtual members?
Thanks,
Michael
|
by: Annie |
last post by:
Hello guys,
I have set the MEMBERSHIP, ROLEMANAGER and PROFILE in my config file as
below.
I just want to use my own sql server 2000 table instead of MSDB.
|
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: =?Utf-8?B?UGF0Qg==?= |
last post by:
Is there a way in ASP.NET 2.0 to have different connection strings settings
in a web.config files that are dynamically used based upon the server that
the web application is running on?
For...
|
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: Andy B |
last post by:
Is it possible to have more than 1 profile section in the same web.config
that use different sql databases for each one? If so, how do you set it up?
I need to know the same thing for Providers.
|
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: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: 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: 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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |