I am using DBExpress in Delphi 2007 to connect to a MySQL5 database server on the net.
It all works OK, until I try and upload a large amount of data. I am trying to insert 8000+ records into the database, one at a time in a loop, in the loop I pass the TSQLConection object to a function along with the data to be inserted.
The function creates a TSQLQuery object and runs the insert query, before freeing the TSQLQuery. when I run it on large sets of data, I get a messages saying there the MySQL server has to many connections. Looking in the process list for the MySQL server I see this.
+---------+------+-------------------------------+--------+---------+------+--------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+---------+------+-------------------------------+--------+---------+------+--------+-----------------------+
| 2962500 | name | myispdomain.co.uk:27812 | data | Sleep | 3 | | [NULL] |
+---------+------+-------------------------------+--------+---------+------+--------+-----------------------+
There is one entriy for every TSQLQuery object I have created, and if I step through the code I can see a new one go in when I run ExecSQL(). I am calling FreeAndNil on the TSQLQuery and have tried calling Close before freeing it.
My MySQL connection settings are as follows
ConnectionName := 'MySQLConnection';
DriverName := 'MySQL';
GetDriverFunc := 'getSQLDriverMYSQL';
KeepConnection := TRUE;
LibraryName := 'dbxmys30.dll';
LoadParamsOnConnect := False ;
LoginPrompt := FALSE;
Name := 'mySQLConnection';
VendorLib := 'LIBMYSQL.DLL';
TableScope := [tsTable,tsView];
Params.Add('DriverName=MySQL');
Params.Add('HostName=www.sample.com');
Params.Add('Database=data');
Params.Add('User_Name=myuser');
Params.Add('Password=mypassword');
Params.Add('BlobSize=-1');
Params.Add('ErrorResourceFile=');
Params.Add('LocaleCode=0000');
Params.Add('Compressed=False');
Params.Add('Encrypted=True');
If I set KeepConnection to False the problem goes away, but the time to run the queries goes up.
Is there a way to get around this?