MYSQL component not working lazarus / 16-Databases ---------------------------------------------------------------------- chuchu · 2006-01-30 10:40 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 · 2006-01-30 16:15 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 · 2006-02-01 01:32 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 · 2006-02-01 06:48 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 · 2006-02-01 08:19 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 ---------------------------------------------------------------------- Vincent Snijders · 2006-02-01 09:17 If you get the exception, open the call stack: View -> Debug Windows -> Call stack. Where does the error occur? (You can do Ctrl-C to copy the call stack). ---------------------------------------------------------------------- Anonymous · 2006-02-01 10:10 Vincent, Thanks for your help, I finally got it ! I should not place the libmysql.dll under the c:\lazarus directory. Because if I do so, all mysql component will only work at design time and will failed if I press the RUN button under Lazarus. Because I think Lazarus will compile the program and run it under the project directory, and that the project directory did not have the libbmysql.dll in it, so it got an EINOutError exception ! I can fixed it by simply put another copy of the libmysql.dll under my projct directory or have it put under windows system directory. Anyway the Window version of Lazarus + Mysql works and I will try the Linux version again. ChuChu ---------------------------------------------------------------------- Anonymous · 2006-02-01 10:45 Hi, I have just resumed my test on Linux+Lazarus+Mysql. I put a MYSQLdatabase, MYSQLdataset,  Datasource, DBGrid. I am using libmysqlclient version 4.0.24. MYSQLdatabase was working fine, I was able to make a connection to the database server. The problem came in when I activate the MYSQLdataset, I got an access violation error, below is my stack trace : #0 strlen at :0 #1 mysql_query at :0 #2 MYSQLDB4_TMYSQLDATASET_$__DOQUERY at :0 #3 MYSQLDB4_TMYSQLDATASET_$__INTERNALOPEN at :0 #4 DB_TDATASET_$__DOINTERNALOPEN at :0 #5 DB_TDATASET_$__SETACTIVE$BOOLEAN at :0 #6 TFORM1__BUTTON1CLICK((^TOBJECT) 0xb79e96c8, (^TFORM1) 0xb79e6278) at main.pas:37 #7 TCONTROL__CLICK((^TCONTROL) 0xb79e96c8) at control.inc:1859 #8 TBUTTONCONTROL__CLICK((^TBUTTONCONTROL) 0xb79e96c8) at buttoncontrol.inc:57 #9 TCUSTOMBUTTON__CLICK((^TCUSTOMBUTTON) 0xb79e96c8) at buttons.inc:187 #10 TBUTTON__CLICK((^TBUTTON) 0xb79e96c8) at buttons.inc:293.......... I fired a button to kick start the connection (line #10) and the debugger stoped at the line (#1) strlen after mysql_query. I have no idea of what to do next, so please help ! ChuChu ---------------------------------------------------------------------- Anonymous · 2006-02-01 15:39 hi, is there some tutorial where i can lern how to use the MySQL Component, pgsql... I really need it. TNX ---------------------------------------------------------------------- matthijs · 2006-02-01 15:45 Quote from: "Anonymous"hi, is there some tutorial where i can lern how to use the MySQL Component, pgsql... I really need it. TNX Did you have a look at this wiki page? This wiki page is more visually orientated. And uses some more components. (I find the last one better, but that might be because I wrote it. ) ---------------------------------------------------------------------- Anonymous · 2006-02-15 14:19 someone speaks spanish?