473,396 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

programming style question (mysql connection)

Hi.

I have to use a database in my c# program.
For that I created a MySqlManager class.
If it is being instanciated a connection will be established like this:

odbcConnection = new OdbcConnection(connectionTarget);
odbcConnection.Open();
(where connectionTarget is a string describing the database access)

I do not close this connection until the main program is terminated.
Is that a good way or is it better to open and close it for every task?

I am asking because I´ve got a problem with the database access.
My program is running 5 or 6 times great and after that I receive an
odbc connection error. I thought that it could be possible that I get
this error if I do not close the connection properly?!?!

After logging in to windows again everything is working fine - for 5 or 6 times...

Thanks for any tips and tricks,
timtos.
Nov 15 '05 #1
3 1618
It sounds like the connection is getting closed correctly...

But as far as the other question, there is a trade-off and both have pros
and cons. When you open/close the database every time - that saves resources
on your database but might appear slower on your front-end. With leaving the
connection open, you need to put extra error handling all over the place in
case the server goes down and you are eating up a connection with every
instance of your application.

Since it's mySQL and in this particular case, I'd say do the open/close
method...

"timtos" <ti****@gmx.de> wrote in message
news:bi**********@news.uni-koblenz.de...
Hi.

I have to use a database in my c# program.
For that I created a MySqlManager class.
If it is being instanciated a connection will be established like this:

odbcConnection = new OdbcConnection(connectionTarget);
odbcConnection.Open();
(where connectionTarget is a string describing the database access)

I do not close this connection until the main program is terminated.
Is that a good way or is it better to open and close it for every task?

I am asking because I´ve got a problem with the database access.
My program is running 5 or 6 times great and after that I receive an
odbc connection error. I thought that it could be possible that I get
this error if I do not close the connection properly?!?!

After logging in to windows again everything is working fine - for 5 or 6 times...
Thanks for any tips and tricks,
timtos.

Nov 15 '05 #2
Thanks for your help!
It helped me!

Greetings,
timtos.

"Frank Drebin" <no*****@imsickofspam.com> wrote in message news:qt**********************@newssvr28.news.prodi gy.com...
It sounds like the connection is getting closed correctly...

But as far as the other question, there is a trade-off and both have pros
and cons. When you open/close the database every time - that saves resources
on your database but might appear slower on your front-end. With leaving the
connection open, you need to put extra error handling all over the place in
case the server goes down and you are eating up a connection with every
instance of your application.

Since it's mySQL and in this particular case, I'd say do the open/close
method...

"timtos" <ti****@gmx.de> wrote in message
news:bi**********@news.uni-koblenz.de...
Hi.

I have to use a database in my c# program.
For that I created a MySqlManager class.
If it is being instanciated a connection will be established like this:

odbcConnection = new OdbcConnection(connectionTarget);
odbcConnection.Open();
(where connectionTarget is a string describing the database access)

I do not close this connection until the main program is terminated.
Is that a good way or is it better to open and close it for every task?

I am asking because I´ve got a problem with the database access.
My program is running 5 or 6 times great and after that I receive an
odbc connection error. I thought that it could be possible that I get
this error if I do not close the connection properly?!?!

After logging in to windows again everything is working fine - for 5 or 6

times...

Thanks for any tips and tricks,
timtos.


Nov 15 '05 #3
Timtos:

The answer depends on what you are doing with it. If you
are using a DataReader or any of the commandfunctions
like ExecuteScalar or NonQuery..

The other consideration is how many calls to the db are
being done.

1) If you are using an Adapter to fill datatables
(disconnected ADO.NET), then the Adapter will take care
of opening and closing the connections...don't do it
yourself.

2) If you are using the connection to submit updates
only, or fire execute scalar commands periodically, then
close it. The main metric to consider is the frequency
with which you'll make trips to the db. Leaving
connections open is the antithetical to the whole ADO.NET
thinking ---- after all, something that works with one
user might turn into a nightmare with 1000 users. Which
begs the next question, how many users do you have? THe
more users you have, the more you'll want to close those
connections.

I hope this helps,

Bill

W.G Ryan
do********@comcast.nospam.net
www.knowdotnet.com
-----Original Message-----
Hi.

I have to use a database in my c# program.
For that I created a MySqlManager class.
If it is being instanciated a connection will be established like this:
odbcConnection = new OdbcConnection(connectionTarget);
odbcConnection.Open();
(where connectionTarget is a string describing the database access)
I do not close this connection until the main program is terminated.Is that a good way or is it better to open and close it for every task?
I am asking because I´ve got a problem with the database access.My program is running 5 or 6 times great and after that I receive anodbc connection error. I thought that it could be possible that I getthis error if I do not close the connection properly?!?!

After logging in to windows again everything is working fine - for 5 or 6 times...
Thanks for any tips and tricks,
timtos.
.

Nov 15 '05 #4

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

Similar topics

0
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
4
by: Reinier Beeckman | last post by:
Hi got the following problem, it's more a programming problem then really a database problem. I have a Database class which connects to a mySQL database on the network. In WebForm1.aspx i connect,...
7
by: Ike | last post by:
Let's say I have a MySQL 4.12 database, opened to the internet on 111.111.111.111 allowing all incoming and outgoing ports. I have a username and password setup, which CAN connect to this database,...
9
by: eholz1 | last post by:
Hello PHP group, I looks like this is a good forum to ask my question. I am using both PHP and MySQL. I would like/am designing a photo database for the web - not heavy duty - not complex,...
5
oll3i
by: oll3i | last post by:
my librarybean package library.ejb; import java.sql.*; import javax.ejb.*; import library.common.*; @Stateless @Remote
3
by: tulika dutta | last post by:
after 8 hrs my MySQL connection with JDBC gets time out. It gives the error java.sql.SQLException: No operations allowed after connection closed.Connection was implicitly closed due to underlying...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
0
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...

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.