Can't connect to MySQL if open/close TZConnection in loop.

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
Jaras
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 25.01.2008, 19:57

Can't connect to MySQL if open/close TZConnection in loop.

Post by Jaras »

I used Zeoslib 6.6.0-beta with Delphi 7 to write some business logics on server side that must create TZConnection on the fly per client call.But if calling is in loop for a long time, I got error 'Can't connect to MySQL server on 127.0.0.1 (10048)' and MySQL stop working for about 1 minute. I try to simulate the following code which make equivalent situation and the same error. Can anyone help? I used MySQL 5.0.45 and its default settings.

for i:=0 to 6000 do {more likely error for more loop count}
begin
Con := TZConnection.Create(nil);
Q := TZQuery.Create(nil);
try
Con.Database := 'myDB';
Con.User := 'root';
Con.Password := 'mypassword';
Con.HostName := '127.0.0.1';
Con.Protocol := 'mysql-5';
Q.Connection := Con;
Q.Close;
Q.SQL.Text := 'select item_id from items';
Q.Open;
finally
Q.Free;
Con.Free;
end;
end;

Jaras
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post by gto »

Well, I think it's a very expected behavior.

Mostly databases have a protection for many connections from the same IP in a little space of time. You should connect once, maybe reconnect a few times later, but never do this loop bases connect/disconnect. Even because you're not calling Con.Disconnect, which should be more readable ;)

Try to increase the max-connections in my.ini configuration file.
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
Taxmax
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 05.09.2007, 17:26

Post by Taxmax »

The max value for max_connections is 16384.

If your application runs on Windows XP or Vista there is a limit of the used (client) ports.

You can check this by write netstat to cmd. Then you will see how many connections are open.

On win XP there is a limit of 4000 concurrently opend ports. And every port will not closed until 240 seconds without activity.

You can incrase this by change two settings in the windows registry:

http://technet.microsoft.com/en-us/libr ... 97382.aspx


I hope this can solve your problem.
Post Reply