473,671 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MySQL too many connections

I am using the following function in a windows service. It is fired off
by a file system watcher component. It works fine, except for I'll copy
in 20 files it has to process at one time. I'll load up MySqlBrowser to
check the data, and it says I'm out of connections. (the database is
remote) The connections don't clear until I stop the service. Any idea
what I'm missing?

Thanks
Chris

Dim myConnection As MySqlConnection
Dim myCommand As MySqlCommand
Try
Dim myConnectionStr ing As String
myConnectionStr ing = ...

myConnection = New MySqlConnection (myConnectionSt ring)
Dim myInsertQuery As String = GenerateQuery()
myConnection.Op en()
myCommand = New MySqlCommand(my InsertQuery)
myCommand.Conne ction = myConnection
myCommand.Execu teNonQuery()
For Each S As String In Errors
myCommand.Comma ndText = "Insert into ImportErrors ....
myCommand.Execu teNonQuery()
Next
Catch ex As Exception
WriteLog(ex.Mes sage)
Finally
If Not myCommand Is Nothing Then
myCommand.Dispo se()
End If
If Not myConnection Is Nothing Then
myConnection.Cl ose()
myConnection.Di spose()
End If
End Try
Nov 21 '05 #1
4 3319
Well,

Are you firing this a bunch? Are you getting a brand new connection each
time?

Do you need a queue? (IN ours we have a queue, so that we don't miss
anything and of course it is multithreaded.)

Thanks,

Shane

"Chris" <no@spam.com> wrote in message
news:e5******** ******@TK2MSFTN GP15.phx.gbl...
I am using the following function in a windows service. It is fired off
by a file system watcher component. It works fine, except for I'll copy
in 20 files it has to process at one time. I'll load up MySqlBrowser to
check the data, and it says I'm out of connections. (the database is
remote) The connections don't clear until I stop the service. Any idea
what I'm missing?

Thanks
Chris

Dim myConnection As MySqlConnection
Dim myCommand As MySqlCommand
Try
Dim myConnectionStr ing As String
myConnectionStr ing = ...

myConnection = New MySqlConnection (myConnectionSt ring)
Dim myInsertQuery As String = GenerateQuery()
myConnection.Op en()
myCommand = New MySqlCommand(my InsertQuery)
myCommand.Conne ction = myConnection
myCommand.Execu teNonQuery()
For Each S As String In Errors
myCommand.Comma ndText = "Insert into ImportErrors ....
myCommand.Execu teNonQuery()
Next
Catch ex As Exception
WriteLog(ex.Mes sage)
Finally
If Not myCommand Is Nothing Then
myCommand.Dispo se()
End If
If Not myConnection Is Nothing Then
myConnection.Cl ose()
myConnection.Di spose()
End If
End Try

Nov 21 '05 #2
SStory wrote:
Well,

Are you firing this a bunch? Are you getting a brand new connection each
time?

Do you need a queue? (IN ours we have a queue, so that we don't miss
anything and of course it is multithreaded.)

Thanks,

Shane

"Chris" <no@spam.com> wrote in message
news:e5******** ******@TK2MSFTN GP15.phx.gbl...
I am using the following function in a windows service. It is fired off
by a file system watcher component. It works fine, except for I'll copy
in 20 files it has to process at one time. I'll load up MySqlBrowser to
check the data, and it says I'm out of connections. (the database is
remote) The connections don't clear until I stop the service. Any idea
what I'm missing?

Thanks
Chris

Dim myConnection As MySqlConnection
Dim myCommand As MySqlCommand
Try
Dim myConnectionStr ing As String
myConnectionStr ing = ...

myConnection = New MySqlConnection (myConnectionSt ring)
Dim myInsertQuery As String = GenerateQuery()
myConnection.Op en()
myCommand = New MySqlCommand(my InsertQuery)
myCommand.Conne ction = myConnection
myCommand.Execu teNonQuery()
For Each S As String In Errors
myCommand.Comma ndText = "Insert into ImportErrors ....
myCommand.Exe cuteNonQuery()
Next
Catch ex As Exception
WriteLog(ex.Mes sage)
Finally
If Not myCommand Is Nothing Then
myCommand.Dispo se()
End If
If Not myConnection Is Nothing Then
myConnection.Cl ose()
myConnection.Di spose()
End If
End Try



I thought about using a Queue. I have it so that each time a new file
is created it files a new thread which does the function that you saw.
So yes if a bunch of files get thrown up at the same time, it would make
many connections. Would you suggest that I have a worker thread that
just polls the queue once a minute?

Chris
Nov 21 '05 #3
Chris,

I did not completly check it, however probably is it that you do the
disposing of your connection not in the right place.

A normal way for using the connection is

Try
create new connection
Catch
'handle errors
Finally
dispose connection
End Try

This will be in the VB2005 version inside one using block as it is with C#

I hope this helps,

Cor
Nov 21 '05 #4
We have a queue.

Are you using the .Synchronized method on the queue? This returns a thread
safe wrapper to the queue.

We enqueue each new file as it comes in. We have one worker thread per
filesystemwatch er (FSW) that does go through the queue handling each file in
the order that it was queued. This is better than a thread per file of
course which would be terrible. (I think you already know that)

Another advantage to enqueuing the file immediately, is that many times a
FSW will fire an event before the file is completely written and this causes
file access problems. Queueing it first seems to take care of this for us.
We have stress tested our app, bombarding it with 1000's of files coming in
one after another with no delay, and with delay, and also in different
directories and multiple FSW's and this seems to work.

HTH,

Shane
"Chris" <no@spam.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
SStory wrote:
Well,

Are you firing this a bunch? Are you getting a brand new connection each
time?

Do you need a queue? (IN ours we have a queue, so that we don't miss
anything and of course it is multithreaded.)

Thanks,

Shane

"Chris" <no@spam.com> wrote in message
news:e5******** ******@TK2MSFTN GP15.phx.gbl...
I am using the following function in a windows service. It is fired off
by a file system watcher component. It works fine, except for I'll copy
in 20 files it has to process at one time. I'll load up MySqlBrowser to
check the data, and it says I'm out of connections. (the database is
remote) The connections don't clear until I stop the service. Any idea
what I'm missing?

Thanks
Chris

Dim myConnection As MySqlConnection
Dim myCommand As MySqlCommand
Try
Dim myConnectionStr ing As String
myConnectionStr ing = ...

myConnection = New MySqlConnection (myConnectionSt ring)
Dim myInsertQuery As String = GenerateQuery()
myConnection.Op en()
myCommand = New MySqlCommand(my InsertQuery)
myCommand.Conne ction = myConnection
myCommand.Execu teNonQuery()
For Each S As String In Errors
myCommand.Comma ndText = "Insert into ImportErrors ....
myCommand.Ex ecuteNonQuery()
Next
Catch ex As Exception
WriteLog(ex.Mes sage)
Finally
If Not myCommand Is Nothing Then
myCommand.Dispo se()
End If
If Not myConnection Is Nothing Then
myConnection.Cl ose()
myConnection.Di spose()
End If
End Try



I thought about using a Queue. I have it so that each time a new file is
created it files a new thread which does the function that you saw. So yes
if a bunch of files get thrown up at the same time, it would make many
connections. Would you suggest that I have a worker thread that just
polls the queue once a minute?

Chris

Nov 21 '05 #5

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

Similar topics

1
8949
by: Titus Cheung | last post by:
Hello, Thought I read somewhere saying that there is a limit to how many connections are available per mySQL account or something like that. Can someone please clarify? I wrote a PHP tool that uses a different PHP file whenever someone hit an HTML form button (ie Submit). It turned out that each one of these PHP files need to re-open the link to the mySQL database by the following snippet or else that particular file won't work:
0
1516
by: Kayra Otaner | last post by:
Hi all, I want to get your opinions on how to increase available/free memory and performance on a heavy volume database server. I have MySQL 4.0.13 running on RH 7.2 replicated to another RH 7.2 using same MySQL version. Recently our master database server (2 AMD Cpu + 2Gb memory + 2Gb swap space) started to suffer from memory outages because of heavy load. During day available free memory is changing from 200Mb to 5Mb and when
0
1671
by: kayra | last post by:
Hi all, I want to get your opinions on how to increase available/free memory and performance on a heavy volume database server. I have MySQL 4.0.13 running on RH 7.2 replicated to another RH 7.2 using same MySQL version. Recently our master database server (2 AMD Cpu + 2Gb memory + 2Gb swap space) started to suffer from memory outages because of heavy load. During day available free memory is changing from 200Mb to 5Mb and when...
0
375
by: Solange Ezveff | last post by:
Object : How to optimize mysql architecture for better web connection ? Hello, I use phpMyAdmin 2.3.2 and MySQL 3.23.58 and I do not know how to well-organize mysql architecture for the user convience and speedness. On my web site, I call all the stucture from one table (5 colums and 50 rows).
3
2229
by: Anthony | last post by:
Hey all, Here's a question for you, my hosts have told me that that one my pages, php, was causing their server to reboot because there were too many open connections and that they should be closed. Now, correct me if I am wrong but I thought that the connections were closed after a minute of inactivity. Does this sound right? Could open connections cause their server to reboot a
1
2823
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work. Despite entering the required lines to "my.ini" (the new my.cnf) through notepad AND MySQL Administrator, the cache does not work. So, today I took a peek at the 'Health' tab in MySQL Administrator.
8
2357
by: Fred | last post by:
Hello, Our website is currently developed in ASP/Mysql 4. The dedicated servers on which it is currently hosted arrive at saturation. Here is their configuration: - 1 server PIV 2,8Ghz 1GB RAM with IIS 5 on Windows 2000 - 1 server Bi-xeon 3Ghz, 512 MB with MySQL 4 on Windows 2003 The website makes approximately 10.000.000 of pages seen and 310.000
4
5359
by: Richard | last post by:
Hi All, I've been trying to build a Ruby-on-Rails plus MySQL application. I'm running Ruby 1.8.2, Rails 1.1.4 and MySQL 5.0.15-nt over WinXP-Pro/SP2. I run under an Administrative account. I tried building the first example from Agile Web Development with Rails, 1st ed. Somehow the DB got corrupted and I couldn't recover. Instead of retrying that, I tried building the first example from Ruby For Rails, which worked fine.
1
13675
by: marcfischman | last post by:
Please help. I have a website running on a linux/apache/mysql/php server. I receive about 8,000-10,000 visitors a day with about 200,000 to 300,000 page views. The server is a RedHat Linux server running PHP 5.x, MySQL 5.x, Apache 2.x We have been suffering from a number of performance issues. Our hosting company has set our max connections to 100, and we are using persistent connections in PHP. At times the mysqld process takes 100%...
3
3573
by: rockdale | last post by:
Hi, all: My web application using MS EntLib for .net 2.0 (Jan 2006) to access my backend database. It works fine with MS SQL 2k. Now we are migrate from MS SQL to mySQL. Everything looks fine except one serious problem: we got the "too many connections" error. Looks like the EntLib did not properly close these connections. on mySQL Administratorserver connectionsThreads I can see a new thread created after a couple of...
0
8476
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
8914
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8670
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...
1
6223
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
5695
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();...
0
4224
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
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.