473,408 Members | 1,876 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,408 software developers and data experts.

Proper database connection disposal methods??

Hi

I have been disposing of my sql connections for some time (as I should) but
when I see samples I noticed that the samples don't close the connection
first. Here is what I do:

sqlconnection.open

Code

sqlconnection.close
sqlconnection.dispose()

-->>
What I see in samples looks like this:

sqlconnection.open

code

sqlconnection.dispose()

-->>

I noticed that in all the samples (where I noticed at all) that no one was
closing the connection first. Should I bother? Is one method right and the
other wrong? Are there any advantages to closing first or should I NOT close
first?

Does anyone know the answer to this?

Thanks.
Nov 19 '05 #1
3 2640
"Roger Twomey" <ro******@vnet.on.ca> wrote in
news:Or**************@TK2MSFTNGP15.phx.gbl:
Hi

I have been disposing of my sql connections for some time (as I
should) but when I see samples I noticed that the samples don't
close the connection first. Here is what I do:

sqlconnection.open

Code

sqlconnection.close
sqlconnection.dispose()

-->>
What I see in samples looks like this:

sqlconnection.open

code

sqlconnection.dispose()

-->>

I noticed that in all the samples (where I noticed at all) that
no one was closing the connection first. Should I bother? Is one
method right and the other wrong? Are there any advantages to
closing first or should I NOT close first?

Does anyone know the answer to this?


Roger,

Dispose() calls Close() if the connection is still open. Use
Reflector (http://www.aisto.com/roeder/dotnet/) to examine how
SqlConnection.Dispose() operates if you're curious.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 19 '05 #2
Thank you.

I suspected that it did.

Do you know if there is any advantage to my closing it explicitly? Do I save
any clock cycles or is it the same either way (except of course that I have
to type more).

Thanks again!

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
"Roger Twomey" <ro******@vnet.on.ca> wrote in
news:Or**************@TK2MSFTNGP15.phx.gbl:
Hi

I have been disposing of my sql connections for some time (as I
should) but when I see samples I noticed that the samples don't
close the connection first. Here is what I do:

sqlconnection.open

Code

sqlconnection.close
sqlconnection.dispose()

-->>
What I see in samples looks like this:

sqlconnection.open

code

sqlconnection.dispose()

-->>

I noticed that in all the samples (where I noticed at all) that
no one was closing the connection first. Should I bother? Is one
method right and the other wrong? Are there any advantages to
closing first or should I NOT close first?

Does anyone know the answer to this?


Roger,

Dispose() calls Close() if the connection is still open. Use
Reflector (http://www.aisto.com/roeder/dotnet/) to examine how
SqlConnection.Dispose() operates if you're curious.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Nov 19 '05 #3
"Roger Twomey" <ro******@vnet.on.ca> wrote in
news:eX**************@TK2MSFTNGP09.phx.gbl:
Thank you.

I suspected that it did.

Do you know if there is any advantage to my closing it
explicitly? Do I save any clock cycles or is it the same either
way (except of course that I have to type more).


Roger,

The performance is going to be essentially the same either way.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 19 '05 #4

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

Similar topics

5
by: DKode | last post by:
I have created an application that will be used for my IT depts. Tasks. I believe I have created the correct architecture but it doesn't feel correct. Could I get opionions if I am headed in the...
2
by: John C | last post by:
I am trying to develop a access database version 2002 from scratch and I am a novice programmer and need much direction. I have been researching and studying about relational database design and...
4
by: Macca | last post by:
Hi, I have an windows forms application that accesses a SQL database I have a few questions as to connecting to the database. This application will run 24 hours a day. It is a monitoring...
5
by: Edwin Knoppert | last post by:
ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. Often, i mean a few times a day, the database is no longer reachable. The appication pool...
4
by: shade73 | last post by:
Hey all. I currently have two seperate namespaces and I'm trying to pass a connection around to them. I want to use the same connection & leave it open for 6 methods & then close it. However, all...
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
22
Frinavale
by: Frinavale | last post by:
How To Use A Database In Your Program Many .NET solutions are database driven and so many of us often wonder how to access the database. To help you understand the answer to this question I've...
7
by: =?Utf-8?B?Um9nZWxpbw==?= | last post by:
hey, I have 2 threads, th and th2, both of them run a method. each of these 2 methods requires database access. sometimes I get an error, that database requires an open connection, and that...
1
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I made web site using asp.net 2.0 Vb.Net. The project depends on database in the local machine. The web site has • Create User Wizard and • Login form When the user is...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.