same code, different providers => different behaviours??

B

Bart

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.ConnectionStrings("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.ConnectionStrings("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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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.
 
B

Bart

Thanks

Göran Andersson said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top