473,569 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scope of objects and best practices

Rob
Rather new to vb.net...

I am wondering if the following is possible and sounds reasonable...

Can connection objects and datasets be defined once (at program load) and be
available for the life of the program ? Posssible ? Bad idea ? Over
simplistic ?

Regarding Connections...
I am not saying that the conncetion should be left open, just defined... in
other words, have it such that...

When Program loads...
Public strConn as String = "define the cnn here"
Public cnn as New SqlConnection(s trConn )

When I want to use the connection...
cnn.Open()
' Do whatever
cnn.Close()

Does Auto garbage collection destroy cnn periodically ?
Regarding Datasets....
Also, may I establish a dataset in the same manner ?

Let's say I have 4 forms that use the same data set in the sasme program....
may I just establish it once, fill it, then use the data from that "fill" on
several forms ? Maybe have a button that would "re-fill" it upon a user's
request ? Would user changes to data within the dataset synch across all
the forms as well since it is the same data set (object) ?

Thanks

Dec 17 '05 #1
3 1392
You can use global variables defined in a module as "Public" or in a class
using shared properties.

As far as being a bad idea, it doesn't all encapsulation of classes that use
these variables but if you're a single programmer and not part of a
programming team then it's up to you how you organize your program so long as
you realize that updates to it a year from now are easier with encapsulation.

One way that I do it is to set up a DataBase Class which does all accessing
of the data base with items like datasets as shared properties.
--
Dennis in Houston
"Rob" wrote:
Rather new to vb.net...

I am wondering if the following is possible and sounds reasonable...

Can connection objects and datasets be defined once (at program load) and be
available for the life of the program ? Posssible ? Bad idea ? Over
simplistic ?

Regarding Connections...
I am not saying that the conncetion should be left open, just defined... in
other words, have it such that...

When Program loads...
Public strConn as String = "define the cnn here"
Public cnn as New SqlConnection(s trConn )

When I want to use the connection...
cnn.Open()
' Do whatever
cnn.Close()

Does Auto garbage collection destroy cnn periodically ?
Regarding Datasets....
Also, may I establish a dataset in the same manner ?

Let's say I have 4 forms that use the same data set in the sasme program....
may I just establish it once, fill it, then use the data from that "fill" on
several forms ? Maybe have a button that would "re-fill" it upon a user's
request ? Would user changes to data within the dataset synch across all
the forms as well since it is the same data set (object) ?

Thanks

Dec 17 '05 #2
Can connection objects and datasets be defined once (at program load) and
be
available for the life of the program ? Posssible ? Bad idea ? Over
simplistic ?

well we are getting now on thin ice .... :-)

As a true OOP aproach is a challenge response modell i.ow. i throw
something in and expect something out everyhting that was used in the middle
to come to this result will be set and destroyed inmediatly after it has
done its job . ( verry simplistic said )

However if you are a programmer who deals with a lot of data that is verry
costly to produce ( in terms that the querys are verry expensive ) you are
probably better of using a Singleton aproach
in wich you can even create a data caching mechanism .
so to give you a straight answer .... i believe that the best aproach is ..
to use as few resources as possible with a maximum on performance for your
app
regards

Michel Posseth [MCP]

"Rob" <rw*****@comcas t.net> wrote in message
news:Np******** *************** *******@comcast .com... Rather new to vb.net...

I am wondering if the following is possible and sounds reasonable...

Can connection objects and datasets be defined once (at program load) and
be available for the life of the program ? Posssible ? Bad idea ? Over
simplistic ?

Regarding Connections...
I am not saying that the conncetion should be left open, just defined...
in other words, have it such that...

When Program loads...
Public strConn as String = "define the cnn here"
Public cnn as New SqlConnection(s trConn )

When I want to use the connection...
cnn.Open()
' Do whatever
cnn.Close()

Does Auto garbage collection destroy cnn periodically ?
Regarding Datasets....
Also, may I establish a dataset in the same manner ?

Let's say I have 4 forms that use the same data set in the sasme
program.... may I just establish it once, fill it, then use the data from
that "fill" on several forms ? Maybe have a button that would "re-fill"
it upon a user's request ? Would user changes to data within the dataset
synch across all the forms as well since it is the same data set (object)
?

Thanks

Dec 17 '05 #3
On 2005-12-17, Rob <rw*****@comcas t.net> wrote:
Rather new to vb.net...

I am wondering if the following is possible and sounds reasonable...

Can connection objects and datasets be defined once (at program load) and be
available for the life of the program ? Posssible ? Bad idea ? Over
simplistic ?
Regarding connections, best practice generally dictates that you create
the connection when you want it and dispose it as soon as possible.
Because of connection pooling there's very little cost to this, and it
keeps the code much, much cleaner and more flexible.

Datasets are a bit more complex, and IMHO the structure of you app
should determine this. If your various forms really are multiple
views on the same dataset, then it's probably better for all forms
to share that dataset, rather than having complex sync operations to
ensure that all four datasets contain the same data or constantly
refilling the dataset just in case another form has changed the
underlying data.

Personally, I'd still shy away from a simple dataset global variable
though. Depending on the app I'd either have some kind of Singleton
class controlling access to the dataset or have the main form "own" the
dataset and pass it to the other forms.

David



Regarding Connections...
I am not saying that the conncetion should be left open, just defined... in
other words, have it such that...

When Program loads...
Public strConn as String = "define the cnn here"
Public cnn as New SqlConnection(s trConn )

When I want to use the connection...
cnn.Open()
' Do whatever
cnn.Close()

Does Auto garbage collection destroy cnn periodically ?
Regarding Datasets....
Also, may I establish a dataset in the same manner ?

Let's say I have 4 forms that use the same data set in the sasme program....
may I just establish it once, fill it, then use the data from that "fill" on
several forms ? Maybe have a button that would "re-fill" it upon a user's
request ? Would user changes to data within the dataset synch across all
the forms as well since it is the same data set (object) ?

Thanks

Dec 18 '05 #4

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

Similar topics

4
2127
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data access module that creates a large disconnected dataset from a database. I want to pass that dataset back to the calling program. And then perhaps I...
4
2398
by: Marc Tanner | last post by:
Hello, I am currently working on a eventhandling system or something similar, and have the problem of loosing scope. I have read many interesting posts on this group and the faq article about closure, but it seems that i have still not understood everything. Below is my attempt to preserve the scope but it's not really nice and i think with...
136
9251
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to...
5
2075
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope function-prototype scope I think(might be wrong):
0
793
by: David Helgason | last post by:
I think those best practices threads are a treat to follow (might even consider archiving some of them in a sort of best-practices faq), so here's one more. In coding an game asset server I want to keep a large number of file revisions of varying sizes (1Kb-50Mb) inside the database. Naturally I want to avoid having to allocate whole...
4
6570
by: jdc_1040 | last post by:
Could someone explain what the scope chain looks like to code running inside eval? (Please no "eval is the devil" essays :) ) Let's say I have a string of JavaScript that looks like this: var myVar1 = 1; var myVar2 = 3; window.someFunc = function() { myVar1++; alertFunc(); }; function anotherFunc() { myVar2++; alertFunc(); }
26
2126
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null); this.property1 = arg; this.property2 = aConstantDefinedGlobally; this.method1 = function (anArg) {
8
1584
by: raylopez99 | last post by:
Hi, Best practices question. When receiving an object passed from another method, is it a good idea to use a shallow copy with a temporary object received on the RHS (right hand side of =), or to use a instantiated object to receive the object on the RHS? Since I may be using the wrong lingo, to put it more concretely.
3
2461
by: John Dann | last post by:
Trying to learn Python here, but getting tangled up with variable scope across functions, modules etc and associated problems. Can anyone advise please? Learning project is a GUI-based (wxPython) Python program that needs to access external data across a serial port. The first thing that I need the program to do when it starts up is to...
0
7701
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...
0
8130
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7979
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...
0
6284
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...
1
5514
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...
0
3653
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...
1
2115
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
0
940
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...

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.