473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class Instantiation

I have aVB.NET application that uses an SQL Server wrapper class to connect
and perform any and all ADO.NET database activities. This is an MDI child
based application where the child forms are in an MDI tabbed environment. So
when a new MDI child form is displayed, a new tab is created much like VS.NET
2005 development environment.

Is it best to dimension a new SQL wrapper class at the module level of a
child form, or should I be creating a new class in every function that
accesses the database? If done at the function level, in theory, the class is
instantiated, used and then released for garbage collection when the function
terminates. As opposed to creating a new wrapper class at the module level
and using that variable in all the functions that access the database. This
would keep the class in memory until the child form is closed.

There may be many functions (10-15) within a given child form that access
the database. So should there be a Dim Myconn as New SQLWrapperClass in
every function or is it better to create the class once at the module level?

Thanks,
--
Scott H.
Apr 10 '06 #1
3 1300
I have a similiar application and instantiate the Database access class in a
module so I can use it in all classes. I probalby will get "Flamed" for this
and if you don't want to do this, you can make all properties and methods
shared in the class. This way, you won't have instantiate the class as a
global.
--
Dennis in Houston
"Scott H." wrote:
I have aVB.NET application that uses an SQL Server wrapper class to connect
and perform any and all ADO.NET database activities. This is an MDI child
based application where the child forms are in an MDI tabbed environment. So
when a new MDI child form is displayed, a new tab is created much like VS.NET
2005 development environment.

Is it best to dimension a new SQL wrapper class at the module level of a
child form, or should I be creating a new class in every function that
accesses the database? If done at the function level, in theory, the class is
instantiated, used and then released for garbage collection when the function
terminates. As opposed to creating a new wrapper class at the module level
and using that variable in all the functions that access the database. This
would keep the class in memory until the child form is closed.

There may be many functions (10-15) within a given child form that access
the database. So should there be a Dim Myconn as New SQLWrapperClass in
every function or is it better to create the class once at the module level?

Thanks,
--
Scott H.

Apr 10 '06 #2
So I could create a global reference to the SQL wrapper class, something like
this:

Module Generic
Public MyConn as New SQLWrapper
End Module

And then use Myconn as a global variable throughout the application. Sounds
like a interesting idea. Is this generally a good practice?
--
Scott H.
"Dennis" wrote:
I have a similiar application and instantiate the Database access class in a
module so I can use it in all classes. I probalby will get "Flamed" for this
and if you don't want to do this, you can make all properties and methods
shared in the class. This way, you won't have instantiate the class as a
global.
--
Dennis in Houston
"Scott H." wrote:
I have aVB.NET application that uses an SQL Server wrapper class to connect
and perform any and all ADO.NET database activities. This is an MDI child
based application where the child forms are in an MDI tabbed environment. So
when a new MDI child form is displayed, a new tab is created much like VS.NET
2005 development environment.

Is it best to dimension a new SQL wrapper class at the module level of a
child form, or should I be creating a new class in every function that
accesses the database? If done at the function level, in theory, the class is
instantiated, used and then released for garbage collection when the function
terminates. As opposed to creating a new wrapper class at the module level
and using that variable in all the functions that access the database. This
would keep the class in memory until the child form is closed.

There may be many functions (10-15) within a given child form that access
the database. So should there be a Dim Myconn as New SQLWrapperClass in
every function or is it better to create the class once at the module level?

Thanks,
--
Scott H.

Apr 10 '06 #3
Yes that works. If you want to use the shared technique then;

public Class SQLWrapper
Shared property ....
Shared method ....
end Class

Then when used in your other classes, etc;

SqlWrapper.prop erty = ....

SqlWrapper does not need to be instantiated.

--
Dennis in Houston
"Scott H." wrote:
So I could create a global reference to the SQL wrapper class, something like
this:

Module Generic
Public MyConn as New SQLWrapper
End Module

And then use Myconn as a global variable throughout the application. Sounds
like a interesting idea. Is this generally a good practice?
--
Scott H.
"Dennis" wrote:
I have a similiar application and instantiate the Database access class in a
module so I can use it in all classes. I probalby will get "Flamed" for this
and if you don't want to do this, you can make all properties and methods
shared in the class. This way, you won't have instantiate the class as a
global.
--
Dennis in Houston
"Scott H." wrote:
I have aVB.NET application that uses an SQL Server wrapper class to connect
and perform any and all ADO.NET database activities. This is an MDI child
based application where the child forms are in an MDI tabbed environment. So
when a new MDI child form is displayed, a new tab is created much like VS.NET
2005 development environment.

Is it best to dimension a new SQL wrapper class at the module level of a
child form, or should I be creating a new class in every function that
accesses the database? If done at the function level, in theory, the class is
instantiated, used and then released for garbage collection when the function
terminates. As opposed to creating a new wrapper class at the module level
and using that variable in all the functions that access the database. This
would keep the class in memory until the child form is closed.

There may be many functions (10-15) within a given child form that access
the database. So should there be a Dim Myconn as New SQLWrapperClass in
every function or is it better to create the class once at the module level?

Thanks,
--
Scott H.

Apr 11 '06 #4

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

Similar topics

7
2481
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M> registrar; }; The constructor of Registrar does the registering when it is initialized.
3
8258
by: Patrick Guio | last post by:
Hi, I have trouble to compile the following piece of code with g++3.4 but not with earlier version // Foo.h template<typename T> class Foo { public:
23
3868
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? Here's what I thought should work, but apparently doesn't: class Foo; void f1(Foo* p)
1
2300
by: Frederiek | last post by:
Hi, When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. Does that mean that the address of the data member is the same for every instance of that class? I would expect so, but I noticed something that makes me doubt a little.
3
2966
by: dischdennis | last post by:
Hello List, I would like to make a singleton class in python 2.4.3, I found this pattern in the web: class Singleton: __single = None def __init__( self ): if Singleton.__single: raise Singleton.__single
3
2963
by: erictham115 | last post by:
Error C2555 c:\C++ projects\stat1\stdmatrix_adapt.h(41) : error C2555: 'std_tools::Matrix_adapter<T>::at': overriding virtual function return type differs and is not covariant from 'ple::imtx_impl<T>::at' //in my program: the derived class template <class T> class Matrix_adapter : public ple::imtx_impl<T{ protected:
12
3120
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is only ever ONE instantiation of this class, and this outside method in a separate thread has to access it. How do i do this?
8
2146
by: Ole Nielsby | last post by:
I want to create (with new) and delete a forward declared class. (I'll call them Zorgs here - the real-life Zorks are platform-dependent objects (mutexes, timestamps etc.) used by a cross-platform scripting engine. When the scripting engine is embedded in an application, a platform-specific support library is linked in.) My first attempt goes here: ---code begin (library)---
4
1903
by: Devon Null | last post by:
I have been exploring the concept of abstract classes and I was curious - If I do not define a base class as abstract, will it be instantiated (hope that is the right word) when a derived class is created? if ( answer == false ) { Would the idea of an abstract class simply be used to enforce integrity of the classes by disallowing the abstract class to be instantiated, or are there other purposes for it? }
4
2492
by: yuanhp_china | last post by:
I define a class in A.h: template <class Tclass A{ public: void get_elem( const T&) ; };
0
9673
marktang
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...
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10002
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 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...
0
9044
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, 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...
1
7543
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 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...
0
6783
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();...
1
4113
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
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.