473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

OdbcDataReader - Problem closing connection

Hi,

I am writing an application using a 3 tier model (Client, Business Layer and
DB)
The DB layer creates a OdbcDataReader object back up to the Client where the
data is read and displayed on the screen.
I then call the Close method of this OdbcDataReader. I had assumed this
closed the connection to the Database, but apparently not (using processlist
in MySQL confirmed the connections were not being closed).
How can I successfully close the Database connection from the Client layer
without having to pass the original Connection object to the Client layer?

Regards,

Steven
Nov 16 '05 #1
6 1832
Steven,

The OdbcConnection is using connection pooling in order to optimise
multiple accesses to the connection pool. Opening and closing a database
connection (for real, instead of fetching it from a pool), can be a very,
very expensive operation.

If you truly need to do this, then you need to set the connection
properties such that connection pooling is disabled.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steven Blair" <st**********@btinternet.com> wrote in message
news:c7*******************@news.demon.co.uk...
Hi,

I am writing an application using a 3 tier model (Client, Business Layer and DB)
The DB layer creates a OdbcDataReader object back up to the Client where the data is read and displayed on the screen.
I then call the Close method of this OdbcDataReader. I had assumed this
closed the connection to the Database, but apparently not (using processlist in MySQL confirmed the connections were not being closed).
How can I successfully close the Database connection from the Client layer
without having to pass the original Connection object to the Client layer?

Regards,

Steven

Nov 16 '05 #2
Nicholas,

Not sure I understand.

I have returned a DataReader from my Database layer:

GetData( ref dr );

Take the data I need from it, then:

dr.Close();

I had originally thought this closed the underlying DB connection.

Is there anyway to close the connection from the Client Layer, since the
Client layer does not have access to Connection objects?

I find it hard to believe that a DataReader could only be closed at the same
level as it was created at.

Regards,

Steven

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uF**************@tk2msftngp13.phx.gbl...
Steven,

The OdbcConnection is using connection pooling in order to optimise
multiple accesses to the connection pool. Opening and closing a database
connection (for real, instead of fetching it from a pool), can be a very,
very expensive operation.

If you truly need to do this, then you need to set the connection
properties such that connection pooling is disabled.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steven Blair" <st**********@btinternet.com> wrote in message
news:c7*******************@news.demon.co.uk...
Hi,

I am writing an application using a 3 tier model (Client, Business Layer

and
DB)
The DB layer creates a OdbcDataReader object back up to the Client where

the
data is read and displayed on the screen.
I then call the Close method of this OdbcDataReader. I had assumed this
closed the connection to the Database, but apparently not (using

processlist
in MySQL confirmed the connections were not being closed).
How can I successfully close the Database connection from the Client layer without having to pass the original Connection object to the Client layer?
Regards,

Steven


Nov 16 '05 #3
Steven,

It's not a matter of the object being closed at the level it is being
created at.

When you call close on the data reader, it does not close the connection
(it shouldn't). The data reader should only close the reader. The state of
the connection should be unchanged.

Now, the other thing to consider is that when you call close on the
connection itself, if connection pooling is being used (which it most likely
is), then you will have to shut that off (however, this is unadvised).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steven Blair" <st**********@btinternet.com> wrote in message
news:c7*******************@news.demon.co.uk...
Nicholas,

Not sure I understand.

I have returned a DataReader from my Database layer:

GetData( ref dr );

Take the data I need from it, then:

dr.Close();

I had originally thought this closed the underlying DB connection.

Is there anyway to close the connection from the Client Layer, since the
Client layer does not have access to Connection objects?

I find it hard to believe that a DataReader could only be closed at the same level as it was created at.

Regards,

Steven

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uF**************@tk2msftngp13.phx.gbl...
Steven,

The OdbcConnection is using connection pooling in order to optimise
multiple accesses to the connection pool. Opening and closing a database
connection (for real, instead of fetching it from a pool), can be a very, very expensive operation.

If you truly need to do this, then you need to set the connection
properties such that connection pooling is disabled.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steven Blair" <st**********@btinternet.com> wrote in message
news:c7*******************@news.demon.co.uk...
Hi,

I am writing an application using a 3 tier model (Client, Business Layer
and
DB)
The DB layer creates a OdbcDataReader object back up to the Client
where the
data is read and displayed on the screen.
I then call the Close method of this OdbcDataReader. I had assumed

this closed the connection to the Database, but apparently not (using

processlist
in MySQL confirmed the connections were not being closed).
How can I successfully close the Database connection from the Client

layer without having to pass the original Connection object to the Client layer?
Regards,

Steven



Nov 16 '05 #4
Steven:

There are a LOT of potential problems with passing datareaders between
layers. I think Kathleen Dollard's words on the subject were "suicide" and
"disaster waiting to happen" You'll notice MS Left the datareader out of
the data access application block. Since they are worthless without
connections, you have to pass a bunch of stuff a lot of places to get this
implementation to work, and for what it's worth, I'd make really sure I
wanted to use this methodology before going live.
"Steven Blair" <st**********@btinternet.com> wrote in message
news:c7*******************@news.demon.co.uk...
Hi,

I am writing an application using a 3 tier model (Client, Business Layer and DB)
The DB layer creates a OdbcDataReader object back up to the Client where the data is read and displayed on the screen.
I then call the Close method of this OdbcDataReader. I had assumed this
closed the connection to the Database, but apparently not (using processlist in MySQL confirmed the connections were not being closed).
How can I successfully close the Database connection from the Client layer
without having to pass the original Connection object to the Client layer?

Regards,

Steven

Nov 16 '05 #5
You may find this helpful..
http://weblogs.asp.net/ssmith/archiv...4/07/5029.aspx
"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:u3**************@tk2msftngp13.phx.gbl...
Steven:

There are a LOT of potential problems with passing datareaders between
layers. I think Kathleen Dollard's words on the subject were "suicide" and
"disaster waiting to happen" You'll notice MS Left the datareader out of
the data access application block. Since they are worthless without
connections, you have to pass a bunch of stuff a lot of places to get this
implementation to work, and for what it's worth, I'd make really sure I
wanted to use this methodology before going live.
"Steven Blair" <st**********@btinternet.com> wrote in message
news:c7*******************@news.demon.co.uk...
Hi,

I am writing an application using a 3 tier model (Client, Business Layer

and
DB)
The DB layer creates a OdbcDataReader object back up to the Client where

the
data is read and displayed on the screen.
I then call the Close method of this OdbcDataReader. I had assumed this
closed the connection to the Database, but apparently not (using

processlist
in MySQL confirmed the connections were not being closed).
How can I successfully close the Database connection from the Client layer without having to pass the original Connection object to the Client layer?
Regards,

Steven


Nov 16 '05 #6
Thanx everyone for the comments. I think I am going to avoid using
DataReader's from now. I should have done a little more homework before
over running my application with them (I have spent most of today
changing over to use DataSets)

Maybe MSDN should have a warning about using DataReaders ;)

Steven
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: flupke | last post by:
Hi, I have a gui (made in wxPython) that enables a user to connect to a server and issue some commands. The problem occurs when i try to disconnect the client. It exits but it doesn't return to...
1
by: cyshao | last post by:
OdbcDataReader How to get UInt32 ? My DB item defined as int(10) , a value is 108371984. It's larger then Int32.MaxValue, but OdbcDataReader seems don't provide GetUInt32(); I tried to use...
0
by: Joaquim Pinto | last post by:
Hello All, I'm developing an application that is using odbcconnection, odbccommand and odbcdatareader to access different tables in two different databases, one Access and the other MySql. The...
13
by: Simon Harvey | last post by:
Hi All, I have a colleague that I wprk with that develops using ASP. I develop using ASP.net. He seems to make sites much faster than me and I am wondering if its because of the two different...
3
by: Paolo Pignatelli | last post by:
I have a Function in a Class File that uses ApplicationBlocks: Public Function GetProductsByCategory(ByVal CategoryID As Integer) Dim myConnection As SqlConnection = New...
7
by: Tumurbaatar S. | last post by:
Is it so important to close database connections? As I understand, after processing a request and sending a response, page object destroyed. So all used connections also destroyed. Yes?
7
by: Martien van Wanrooij | last post by:
I have been faced a couple of times with the situation that I wanted to write a script and was worried about a too frequent opening and closing mysql connections. To give some examples: 1)I...
5
by: zacks | last post by:
If I close and dispose an ODBCConnection object, shouldn't the connection actually close? I have found that even after closing and disposing an ODBCConnection, the database it was connected to...
5
by: khalid Ahmed | last post by:
I'm attempting to execute a SQL SELECT query but it doesn't seem to be returning any records. I've confirmed that the connection is actually opening and when I tried to execute the same query on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.