473,466 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Programming Practicies

I'm an old VB6 guy and in VB6 I could Open up a DataConnection object as
PUBLIC and use it anywhere in the application.

What do I do in C# or what is the "right" way. should I be creating a new
connection EVERY time I need something from the Database?

Just basics.... Thanks In Advance.
Doug
Nov 16 '05 #1
3 991
Ive found the new database wizard is excellent for making a database, I
cant find it with the version Im using on C#, but it lets you specify the
type and identify the database *.mdb and test it, then it writes some code
for you.

What I found was that opening the main database, then copying to a temp
database, closing the main, then you can access the temp db.

As to the connection staying open? Im interested to learn the answer, I try
to close it as a rule for each access, but it might depend on the complexity
of the application. If its bank data? One would want more safeguards in
place obviously, and ways to track each transaction.
"Doug Durrett" <kc****@durrettonline.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I'm an old VB6 guy and in VB6 I could Open up a DataConnection object as
PUBLIC and use it anywhere in the application.

What do I do in C# or what is the "right" way. should I be creating a new
connection EVERY time I need something from the Database?

Just basics.... Thanks In Advance.
Doug

Nov 16 '05 #2
For the most part opening and closing the connection to a database is
preferable to leaving it open for extended periods of time. Basically
it comes down to how frequently you will need to use the connection vs
many connections to your database you want to take up. What you have to
keep in mind is that most databases have some form of maximum user
connections (whether it is due to licensing or locking) and when your
application opens one up when it starts and doesn't close it until the
application is closed then that is one less connection that is available
for others to use.

Imagine that you have five connections available to your database and
ten database users... if you leave the connection open for your
application you can only get half the users into the system before it
locks the others out. At that point you either have to redesign or you
have to buy more licenses. However if you open and close connections
only as needed you'll find that five licenses is more than enough to
handle your users (unless the application constantly hammers the
database) and will actually handle a lot more users as well.

This is my 2 cents.

Have A Better One!

John M Deal, MCP
Necessity Software

Doug Durrett wrote:
I'm an old VB6 guy and in VB6 I could Open up a DataConnection object as
PUBLIC and use it anywhere in the application.

What do I do in C# or what is the "right" way. should I be creating a new
connection EVERY time I need something from the Database?

Just basics.... Thanks In Advance.
Doug

Nov 16 '05 #3
Connection pooling means you really don't have to worry about constantly
closing and re-opening connections. On the other hand if you are writing,
say, a batch processing utility that will hit the database continuously for
an hour, then it probably is an advantage to hold open a single connection
for the whole run.

It all depends on the access pattern -- if you're hitting the DB hard and
continuous, then holding a connection open for at least that operation
probably makes sense. But for typical CRUD operations, it's best to rely on
connection pooling.

--Bob

"Doug Durrett" <kc****@durrettonline.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I'm an old VB6 guy and in VB6 I could Open up a DataConnection object as
PUBLIC and use it anywhere in the application.

What do I do in C# or what is the "right" way. should I be creating a new
connection EVERY time I need something from the Database?

Just basics.... Thanks In Advance.
Doug

Nov 16 '05 #4

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

Similar topics

5
by: Martin | last post by:
When was inheritance intruduced into object oriented programming? More generally, does anyone know or have any sources on when the different features were introduced into object oriented...
12
by: G. | last post by:
Hi all, During my degree, BEng (Hons) Electronics and Communications Engineering, we did C programming every year, but I never kept it up, as I had no interest and didn't see the point. But now...
3
by: user | last post by:
Hi all, At the outset, I regret having to post this slightly OT post here. However, I strongly feel that people in this group would be the best to advise me on my predicament. I am working as...
134
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've...
42
by: Kevin Spencer | last post by:
Is it just me, or am I really observing a trend away from analysis and probem-solving amongst programmers? Let me be more specific: It seems that every day, in greater numbers, people are coming...
2
by: - | last post by:
I kinda like programming (Java is the only language I know) but have not been able to develop a complete software or get anywhere close to it. The reason why I like it is because it gives me great...
9
by: uttre | last post by:
hai to all, i did some programming in Lisp (6 months) & next i want to learn C++. i searched all the archives of "comp.lang.c++" & ACCU too & decided "C++ Primer" 3/e as my text book....
7
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already...
30
by: Jakle | last post by:
I have been googling, but can seem to find out about C GUI libraries. My main platform is Windows, but it would be nice to find a cross platform library. I've been programming with php, which...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.