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