Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > same code, different providers => different behaviours??

Reply
Thread Tools

same code, different providers => different behaviours??

 
 
Bart
Guest
Posts: n/a
 
      03-22-2007
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



 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      03-22-2007
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
 
Reply With Quote
 
 
 
 
Bart
Guest
Posts: n/a
 
      03-22-2007
Thanks

"Göran Andersson" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird issue, same code, same browser, two different apache servers,very different css bluebaron HTML 3 11-04-2009 07:13 PM
Multiple Profiles and providers in the same web.config? Andy B ASP .Net 1 02-11-2009 08:19 PM
running same script on same data on two different machines -->different result Christopher Brewster Python 5 11-14-2008 08:19 PM
pix VPN with different CA providers? Eugene Vekua Cisco 5 05-26-2004 09:31 AM
same code produces different decimal symbol on different computers with same settings ASP General 2 12-29-2003 02:29 PM



Advertisments