Greetings,
I got a class that wraps the System.Data.Sql Client.SqlConne ction class (no
COM interaction). I'm not sure if I'm supposed to implement the IDisposable
pattern for this wrapper or not. Since one of it's members (SqlConnection)
implements this interface, I'm thinking maybe I ought to. But on the other
hand, those unmanaged resources has already been wrapped in the
SqlConnection class...
If so, how would my Dispose method look like?
I'm not really sure if I should look at SqlConnection as a managed or
unmanaged resource...
--
Thanks
/Billy 2 4819
Only implement I disposable if you have resources which need to be
cleaned up after use. A popular one would be any open Streams, etc.
So in your wrapper, if you have things that need to be "cleaned" up,
then you'll want to implement IDisposable.
It's as easy as inheriting from it and creating the method
public void Dispose()
{
// do your cleanup here
}
It sounds like you should probably, since you're wrapping
SqlConnection. At the very minimum, have your dispose call your
SqlConnections' s dispose function.
I'm not an expert on the topic, but those are my thoughts. Someone
else may have more sound reasoning.
On Fri, 5 Dec 2003 20:22:53 +0100, "Billy Porter" <bi***@xymox.co m>
wrote: Greetings,
I got a class that wraps the System.Data.Sql Client.SqlConne ction class (no COM interaction). I'm not sure if I'm supposed to implement the IDisposable pattern for this wrapper or not. Since one of it's members (SqlConnection) implements this interface, I'm thinking maybe I ought to. But on the other hand, those unmanaged resources has already been wrapped in the SqlConnectio n class...
If so, how would my Dispose method look like? I'm not really sure if I should look at SqlConnection as a managed or unmanaged resource...
If your class creates the SqlConnection (for example) only as needed and
makes sure it cleans it up in try...finally blocks , using(), etc. there is
no need for it to implement IDisposeable itself, since there isn't really
anything to clean up at that point.
On the other hand, if your class has a instantiation of the SqlConnection
scoped to the class for some reason then it needs to be IDisposeable so it
can clean that up.
The former approach is generally recommended anyway (for resource
conservation), so you should rarely have to implement IDisposeable.
<om***@yahoo.co m> wrote in message
news:dh******** *************** *********@4ax.c om... Only implement I disposable if you have resources which need to be cleaned up after use. A popular one would be any open Streams, etc.
So in your wrapper, if you have things that need to be "cleaned" up, then you'll want to implement IDisposable.
It's as easy as inheriting from it and creating the method
public void Dispose() { // do your cleanup here }
It sounds like you should probably, since you're wrapping SqlConnection. At the very minimum, have your dispose call your SqlConnections' s dispose function.
I'm not an expert on the topic, but those are my thoughts. Someone else may have more sound reasoning.
On Fri, 5 Dec 2003 20:22:53 +0100, "Billy Porter" <bi***@xymox.co m> wrote:
Greetings,
I got a class that wraps the System.Data.Sql Client.SqlConne ction class
(noCOM interaction). I'm not sure if I'm supposed to implement the
IDisposablepattern for this wrapper or not. Since one of it's members
(SqlConnection)implements this interface, I'm thinking maybe I ought to. But on the
otherhand, those unmanaged resources has already been wrapped in the SqlConnectio n class...
If so, how would my Dispose method look like? I'm not really sure if I should look at SqlConnection as a managed or unmanaged resource... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alper AKCAYOZ |
last post by:
Hello Esteemed Developers and Experts,
I have been using Microsoft Visual C++ .NET for 1 year. During this time,
I have searhed some topics over internets. Most of the topics about .NET is
related to C# and Visual Basic .NET. There are less documents about Visual
C++ .NET or Managed C++.
I wonder the reasons of below questions:
1) Is C# more powerful than Managed C++ and Visual C++ .NET?
2) Is Microsoft intending to support C# and...
|
by: Henrik Dahl |
last post by:
Hello!
After I've finished using an instance of the SqlCommand class, should I then
invoke Dispose() on the instance. I suppose so, as there is a Dispose
method, but what does it actually release?
I would basically prefer to skip invoking Dispose() as this will free me
from determining when the usage actually has finished.
|
by: 0to60 |
last post by:
I'm trying to create a .dll with VS.NET 2003 Architect that contains a math
computational component. I need the guts of the thing to be in native code,
as performance is key for that part. But, I need a .net wrapper because
this "calculator" is actually a component used by an enterprise app written
entirely in .net.
What I want to do is have one project. I've created an MC++ .dll project.
Its got a __gc class (the wrapper) and a...
|
by: WithPit |
last post by:
I am trying to create an Managed C++ Wrapper around an unmanaged library
which contains C++ code.
Some of the unmanaged methods returns an returntype which is of the abstract
base type (for example unmanagedObject). How can i convert this to the
managed abstract basetype?
Hope somebody can help me
Thanx
|
by: clintonG |
last post by:
Documentation tells me how but not when, why or where...
<%= Clinton Gallagher
http://msdn2.microsoft.com/en-us/library/saxz13w4(VS.80).aspx
| |
by: Mark |
last post by:
If your class implements IDisposable, I was told that this increases the
speed with which your class is garbage collected. Is this true? And if so,
how much "time" does it save? Assume that we are dealing with 100% managed
code and that the clean-up is of big inmemory data structures.
Thanks in advance.
Mark
|
by: Varangian |
last post by:
Hello,
was wondering of how to dispose of managed resources?
or referencing every member of a class to null will release
resources...?
http://www.marcclifton.com/tabid/79/Default.aspx
http://www.codeproject.com/managedcpp/garbage_collection.asp - sources
|
by: =?Utf-8?B?RWR3YXJkUw==?= |
last post by:
I would greatly appreciate some help on passing managed object into unmanaged
code.
I need to pass a reference (address of) of a managed class into unmanaged
code (written by a thrid party). The 3rd party unmanaged DLL will pass this
reference into standard Win32 unmanaged static callback function in my code.
Inside this unmanaged callback function I need to cast this unmnaged pointer
that I have received from 3rd party back into the...
|
by: Bob Altman |
last post by:
Hi all,
We have a native class modeled after the System::Exception class, and all
exceptions that we throw derive from this class. For now this class is
quite simple: just Description and InnerException public members. One of
these days I'll dig into how to implement a StackTrace property (I assume
that this is possible using something like dbghelp.dll, but I've never had
the time to look into it).
I've recently written a managed...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |