Home All Groups Group Topic Archive Search About
Author
10 Apr 2006 12:35 PM
Scott H.
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.

Author
10 Apr 2006 1:01 PM
Dennis
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


Show quoteHide quote
"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.
Author
10 Apr 2006 3:35 PM
Scott H.
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.


Show quoteHide quote
"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.
Author
11 Apr 2006 1:49 AM
Dennis
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.property = ....

SqlWrapper does not need to be instantiated.

--
Dennis in Houston


Show quoteHide quote
"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.