Forum > Databases
MYSQL component not working
chuchu:
Hi,
I was not able to have the mysql component working !
I follow the database tutorial and I can successfully get the text version of mysql4.0 working using fpc.
However, when I came accross the component version of Mysql, to be exact the SQLDB component. I can compiled the sample source (http://wiki.lazarus.freepascal.org/index.php/MySQLDatabases) and make it run. However, everytime when it call SQLQuery1.Open, I got an access violation. Can anyone help me.
I was using Linux, with Lazarus 0.9.11 beat (SVN rev. 8643M) with SQLDB from the same package. Mysql client 4.0.24 and the name of the mysql client library that I am using was : libmysqlclient.so.12.0.0
Thanks !
ChuChu
matthijs:
Access violation emerge when you do not connect correctly to the database server. (At least that is my experience.) Make sure you have the correct credentials supplied to the MySQL40Connection. Check this in the following way:
In design time enter username and password and try to connect.
If this works connect the SQLTransaction and activate it.
Then finally open your query. (This should not be a problem anymore.)
Anonymous:
Hi,
I am sure that the credentials that I supplied is OK.
I filled in the host,user,password field and changed the MySQLConnection's active propertity to True at design time, it works fine.
But when I changed the SQLQuery's (which use the MySQL Connection+Transaction mentioned above and a simple SQL statement : show databases) active property to True, an Access Violation dialogue box popup !
The result is the same when I use the sample test program download from the web :
...
// Set the connection parameters.
MySQLConnection1.HostName := HostEdit.Text;
MySQLConnection1.UserName := UserEdit.Text;
MySQLConnection1.Password := PasswdEdit.Text;
MySQLConnection1.DatabaseName := 'mysql'; // MySQL is allways there!
ShowString('Opening a connection to server: ' + HostEdit.Text);
MySQLConnection1.Open; // <------------- this works
// First lets get a list of available databases.
if MySQLConnection1.Connected then begin
ShowString('Connected to server: ' + HostEdit.Text);
ShowString('Retreiving list of available databases.');
SQLQuery1.SQL.Text := 'show databases';
ShowString ('Open DataBase !');
SQLQuery1.Open; // <-------- Failed at here ! Access Violation
ShowString ('Total Record : ' + inttostr(SQLQuery1.RecordCount));
matthijs:
Try make a new project. Place a TMySQL??Connection on your form. Fill the properties HostName, DatabaseName (mysql), UserName and Password. Try and connect to the server.
Then place a SQLTransaction on your form and fill the MySQL??Connection property with the SQLTransaction. Then set the SQLTransaction to activ.
If this al works place a SQLQuery on your form, connect it to your MySQL??Connection and fill the SQL with select * from db. Open the SQLQuery.
An important thing to take care of is the usage of the proper MySQLConnection component. With the latest version of Lazarus there are now 3 MySQLConnection components. If you have MySQL 4.1 you should use a TMySQL41Connection, if you haven MySQL 4.0 running use the TMySQL40Connection!
Anonymous:
Thanks for your reply.
I try MySQLconnection with a correct set of username/password, it works at design time which means that I have no error found when I set the active property to TRUE. When a SQLQuery is added (with a SQLTransaction and a correct syntax SQL statement) then when I activate the SQLQuery, the access violation dalogue box pops out. I was using the linux version, so I got only one MySQLconnection, and there is no 40, 41 or 50 connections. So I assume that it should be a 40 version and the mysql library that I use was version 4.0.24.
Without any luck, I then switch to the WindowXP environment to see if MYSQL works under Lazarus. Below is what I got :
I got the latest binary 0.9.11 beta (8642M), install it, got the V4.0 libmysql.dll and place it in the c:\lazarus directory where Lazarus was installed. Got the sample Mysql Database program (ptrymysql.lpi) from the Web. Becase there are 3 TMYSQLXXConnection, so I just replace the TMYSQLCOnnection under the ptrymysql project with a TMYSQL40Connection. I then complie and run the sample program. When I key in the host/user/password and press the connect button, I got an exception EInOutError.
I then download a version 5.0 libmysql.dll and change the MYSQL40connection to MYSQL50connection, but I got the same erorr :(
Finally, I decide to start it all over again : I create a new application, drop a TMYSQL40Connection (because I have just switched back to the ver 4.0 libmysql.dll), setup the host/user/password. Then drop a TSQLtransaction, link it up with the TMYSQL40Connection, drop a TSQLQuery, TDataSource, DBGrid. Well, I saw my DBGrid all filled with data that was on the MYSQL server :) Everything is working in Design time.
I then press the RUN button to create a complied version of my program. But Lazarus stop and tell me that there is an EInOutError exception, a message that was exactly the same as the one I got when I trying to run the sample application.
So what's wrong ? Please help :(
ChuChu
Navigation
[0] Message Index
[#] Next page