.NETGURU
Why no error closing datareader or connection objects?
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-oledb' list.


TBrewi@aol.com
-- Moved from [aspngdata] to [ngfx-oledb] by Marcie Jones <Click here to reveal e-mail address> --

In the following code, I expected to get an error on Lines 13 or 15 because I
specified CommandBehavior.CloseConnection on Line 7. Leave it to me to
worry about NOT getting an error! Shouldn't I get a runtime error trying to
close a reader or connection that's already closed?

L1 Dim objConnection As New OleDbConnection()
L2 objConnection.ConnectionString = ...and.so.on...
L3 Dim strSQL As String = "SELECT * FROM Clients"
L4 Dim objCommand As New OleDbCommand(strSQL, objConnection)
L5 Dim objDataReader As OleDbDataReader
L6 objConnection.Open()
L7 objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)
L8 objDataReader.Read()
L9 With objDataReader
L10 strLastName = .Item("LastName").ToString
L11 ...and.so.on...
L12 End With
L13 objDataReader.Close()
L14 objDataReader = Nothing
L15 objConnection.Close()
L16 objCommand = Nothing

As a .NET newbie, I welcome any other comments on how to do the above in the
most efficient way.

-- Tim :)

Timothy M. Brewi

Reply to this message...
 
    
Daniel Naumann
Tim,

I don't really remember the answer but there were several detailed discussions
of this topic over on the ASPNG-architecture list. If you search the archives
you'll find a tonne of information (it was a few months ago.......).

Daniel.

-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: 24-Jul-2002 05:28
To: ngfx-oledb
Subject: [ngfx-oledb] Why no error closing datareader or connection
objects?

-- Moved from [aspngdata] to [ngfx-oledb] by Marcie Jones
<Click here to reveal e-mail address> --

In the following code, I expected to get an error on Lines 13 or 15 because I
specified CommandBehavior.CloseConnection on Line 7. Leave it to me to
worry about NOT getting an error! Shouldn't I get a runtime error trying to
close a reader or connection that's already closed?

L1 Dim objConnection As New OleDbConnection()
L2 objConnection.ConnectionString = ...and.so.on...
L3 Dim strSQL As String = "SELECT * FROM Clients"
L4 Dim objCommand As New OleDbCommand(strSQL, objConnection)
L5 Dim objDataReader As OleDbDataReader
L6 objConnection.Open()
L7 objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)
L8 objDataReader.Read()
L9 With objDataReader
L10 strLastName = .Item("LastName").ToString
L11 ...and.so.on...
L12 End With
L13 objDataReader.Close()
L14 objDataReader = Nothing
L15 objConnection.Close()
L16 objCommand = Nothing

As a .NET newbie, I welcome any other comments on how to do the above in the
most efficient way.

-- Tim :)

Timothy M. Brewi
| [ngfx-oledb] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-oledb.asp = JOIN/QUIT

Reply to this message...
 
 
System.Data.CommandBehavior
System.Data.OleDb.OleDbCommand
System.Data.OleDb.OleDbConnection
System.Data.OleDb.OleDbDataReader




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification