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.ExecuteRea der" (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.Ole Db
Partial Class studalres
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim oConnection As OleDbConnection
Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader
Dim sql As String
oConnection = New OleDbConnection ()
oConnection.Con nectionString =
System.Configur ation.Configura tionManager.Con nectionStrings( "oledbdemo").To String()
oConnection.Ope n()
sql = "SELECT pc.naam FROM pc ;"
comd = New OleDbCommand(sq l, oConnection)
dtreader = comd.ExecuteRea der
'dtreader.Close ()
sql = "SELECT pc.naam FROM pc ;"
comd = New OleDbCommand(sq l, oConnection)
dtreader = comd.ExecuteRea der
dtreader.Close( )
oConnection.Clo se()
End Sub
End Class
2) with SqlClient :
----------------
Imports System.Data
Imports System.Data.sql client
Partial Class studalres
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim oConnection As SqlConnection
Dim comd As SqlCommand
Dim dtreader As SqlDataReader
Dim sql As String
oConnection = New SqlConnection()
oConnection.Con nectionString =
System.Configur ation.Configura tionManager.Con nectionStrings( "sqlclientdemo" ).ToString()
oConnection.Ope n()
sql = "SELECT pc.naam FROM pc ;"
comd = New SqlCommand(sql, oConnection)
dtreader = comd.ExecuteRea der
'dtreader.Close ()
sql = "SELECT pc.naam FROM pc ;"
comd = New SqlCommand(sql, oConnection)
dtreader = comd.ExecuteRea der
'here is the error
dtreader.Close( )
oConnection.Clo se()
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.ExecuteRea der" (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.Ole Db
Partial Class studalres
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim oConnection As OleDbConnection
Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader
Dim sql As String
oConnection = New OleDbConnection ()
oConnection.Con nectionString =
System.Configur ation.Configura tionManager.Con nectionStrings( "oledbdemo").To String()
oConnection.Ope n()
sql = "SELECT pc.naam FROM pc ;"
comd = New OleDbCommand(sq l, oConnection)
dtreader = comd.ExecuteRea der
'dtreader.Close ()
sql = "SELECT pc.naam FROM pc ;"
comd = New OleDbCommand(sq l, oConnection)
dtreader = comd.ExecuteRea der
dtreader.Close( )
oConnection.Clo se()
End Sub
End Class
2) with SqlClient :
----------------
Imports System.Data
Imports System.Data.sql client
Partial Class studalres
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim oConnection As SqlConnection
Dim comd As SqlCommand
Dim dtreader As SqlDataReader
Dim sql As String
oConnection = New SqlConnection()
oConnection.Con nectionString =
System.Configur ation.Configura tionManager.Con nectionStrings( "sqlclientdemo" ).ToString()
oConnection.Ope n()
sql = "SELECT pc.naam FROM pc ;"
comd = New SqlCommand(sql, oConnection)
dtreader = comd.ExecuteRea der
'dtreader.Close ()
sql = "SELECT pc.naam FROM pc ;"
comd = New SqlCommand(sql, oConnection)
dtreader = comd.ExecuteRea der
'here is the error
dtreader.Close( )
oConnection.Clo se()
End Sub
End Class
Comment