Recent

Author Topic: MySQL Connection Error: External:SIGSEGV  (Read 11168 times)

obi8

  • New member
  • *
  • Posts: 8
MySQL Connection Error: External:SIGSEGV
« on: February 10, 2017, 11:04:02 am »
Hello guys,
i have a problem with mysql connection in pascal.
If i run the programm i get a error message:
"Programm Kochbuch have triggered a exception: External: SIGSEGV in
main.pas at line 78 with DataModule1.MySQL57Connection"

I installed lazarus from this page: http://wiki.lazarus.freepascal.org/Getting_Lazarus svn version.
Then i install the sqldb package in lazarus.
I add a DataModul to my project and put a mysqlconnection on this and i add a SQLDBLibrarayLoader where i add the the mysql library.

Can any one help me with this message?

Code: Pascal  [Select][+][-]
  1. with DataModule1.MySQL57Connection1 do
  2.   begin
  3.     HostName := Adresse;
  4.     UserName := '****';
  5.     Password := '****';
  6.     DatabaseName := DBName;
  7.     Port := Port;
  8.     Open;
  9.     if Connected then ShowMessage('Verbunden');
  10.   end;

My System:
Fedora 25 x86_64
Lazarus 1.7 svn version
FPC 3.0.3
MariaDB Database

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: MySQL Connection Error: External:SIGSEGV
« Reply #1 on: February 10, 2017, 11:57:25 am »
Code: Pascal  [Select][+][-]
  1. with DataModule1.MySQL57Connection1 do
  2.   begin
  3.     HostName := Adresse;
  4.     UserName := '****';
  5.     Password := '****';
  6.     DatabaseName := DBName;
  7.     Port := Port;
  8.     Open;
  9.     if Connected then ShowMessage('Verbunden');
  10.   end;
What do you expect will happen on line 7?
Port := Port ?

That's the evilness of using with. You probably have a parameter of variable Port. But if you use with you can't reach the variable/parameter Port because you get the port of DataModule1.MySQL57Connection1.

I would suggest:
Code: Pascal  [Select][+][-]
  1. DataModule1.MySQL57Connection1.HostName := Adresse;
  2. DataModule1.MySQL57Connection1.UserName := '****';
  3. DataModule1.MySQL57Connection1.Password := '****';
  4. DataModule1.MySQL57Connection1.DatabaseName := DBName;
  5. DataModule1.MySQL57Connection1.Port := Port;
  6. DataModule1.MySQL57Connection1.Open;
  7. if DataModule1.MySQL57Connection1.Connected then ShowMessage('Verbunden');
Or rename your variable/parameter Port to something else (like APort).
In that case you can use it within the with-block.

obi8

  • New member
  • *
  • Posts: 8
Re: MySQL Connection Error: External:SIGSEGV
« Reply #2 on: February 10, 2017, 12:04:17 pm »
Thanks, for you're post.
Port ist a string with the value from a ini file.
Ah i see port must be from type longword damn. :-)

But if i commet out the line 7, the programm don't work.

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: MySQL Connection Error: External:SIGSEGV
« Reply #3 on: February 10, 2017, 12:07:30 pm »
But if i commet out the line 7, the programm don't work.

No, port needs to be set (if there isn't a default).
You could try Port := 3306; (which is normally the default for MySQL)

Normally you also pass the Port along with your Adresse and DBName. From where do you get that Adresse?

obi8

  • New member
  • *
  • Posts: 8
Re: MySQL Connection Error: External:SIGSEGV
« Reply #4 on: February 10, 2017, 12:14:08 pm »
I get the server and database information from a IniFile.

This is the code with the ini file and mysql connection:
Code: Pascal  [Select][+][-]
  1. Ini := TIniFile.Create(ChangeFileExt(Application.Name, 'config.ini'));
  2.   try
  3.     Adresse := Ini.ReadString('Server', 'Adresse', '192.168.122.1');
  4.     APort       := Ini.ReadString('Server', 'Port', '3306');
  5.     SQLID       := Ini.ReadString('Datenbank', 'ID', '3306');
  6.     DBName      := Ini.ReadString('Datenbank', 'Name', 'Kochbuch');
  7.   finally
  8.     Ini.Free
  9.   end;
  10.  
  11.   with DataModule1.MySQL57Connection1 do
  12.   begin
  13.     HostName := Adresse;
  14.     UserName := 'Obi8';
  15.     Password := 'DarthVader89';
  16.     DatabaseName := DBName;
  17.     Port := StrtoInt(APort);
  18.     Open;
  19.     if Connected then ShowMessage('Verbunden');
  20.   end;

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: MySQL Connection Error: External:SIGSEGV
« Reply #5 on: February 10, 2017, 12:21:50 pm »
You could make it this:
Port := StrtoIntDef(APort, 3306);

In that case, if APort is not a valid integer as string, it will revert to port 3306.

But... does it work now for you?
If not... what line exactly is the error on (I can't see what line "78" is).
Did you include the correct MySQL-dlls?
Do you compile for 32bit of 64bit?
Do you have the drivers for mysql for that same bitness?
Is there a firewall on 192.168.122.1 which can block the connection?

Did you try to connect to the mysql-server with an external MySQL-manager on your workstation?
For example MySQL Workbench locally.

obi8

  • New member
  • *
  • Posts: 8
Re: MySQL Connection Error: External:SIGSEGV
« Reply #6 on: February 10, 2017, 12:31:33 pm »
i changed it to Port := StrToIntDef(APort, 3306).

But dont work. I get the same error.

Sorry to write line 78, this is on my pc. In the last code example it is line 11
"with DataModule1.MySQL57Connection".

I have a vm with windows 7 and a rad studio from school and the same programm.
With this i can connect from the vm to my host Database without errors. So i dont think that was a firewall problem.

In the "SQLDBLibraryLoader" i include this library: "libmysqlclient.so.18.0.0".
I copy the library in the project folder.

I compile it for 64bit.


rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: MySQL Connection Error: External:SIGSEGV
« Reply #7 on: February 10, 2017, 12:40:56 pm »
I have a vm with windows 7 and a rad studio from school and the same programm.
With this i can connect from the vm to my host Database without errors. So i dont think that was a firewall problem.
Ok, then it's not a problem at the server side (I take it the MySQL is on another machine on your internal network).

Quote
In the "SQLDBLibraryLoader" i include this library: "libmysqlclient.so.18.0.0".
I copy the library in the project folder.
I compile it for 64bit.
And now you try to convert it to Linux.... (that would have been useful information in your first post :) )

Putting "libmysqlclient.so.18.0.0" in your project directory isn't going to work on Linux. It does work on Windows but the LoadLibrary on Linux works differently.

Linux doesn't check your project directory for the library.
See: http://wiki.freepascal.org/Lazarus/FPC_Libraries
Quote
Linux
A dynamic library filename always has the form 'lib'+packagename+'.so'+version. For example: libz.so.1 and libz.so.1.2.2.
Linux searches a library in this order:
  • first in the paths of the environment variable LD_LIBRARY_PATH
  • then in /lib
  • then /usr/lib
  • finally the paths of /etc/ld.so.conf
So you need to check what library is used for MySQL 5.7.
But first... you mentioned libmysqlclient.so.18.0.0.
That's the library for MySQL 5.6, NOT 5.7. It makes a world of difference.
(I see you used a mysql57connection in your program !!!!)

From mysql.inc:
Code: Pascal  [Select][+][-]
  1. {$IFDEF Unix}
  2.   {$DEFINE extdecl:=cdecl}
  3.   const
  4.     mysqllib = 'libmysqlclient.'+sharedsuffix;
  5.   {$IF DEFINED(mysql57)}
  6.     mysqlvlib = mysqllib+'.20';
  7.   {$ELSEIF DEFINED(mysql55) or DEFINED(mysql56)}
  8.     mysqlvlib = mysqllib+'.18';
  9.   {$ELSEIF DEFINED(mysql51)}
  10.     mysqlvlib = mysqllib+'.16';
  11.   {$ELSEIF DEFINED(mysql50)}
  12.     mysqlvlib = mysqllib+'.15';
  13.   {$ELSEIF DEFINED(mysql41)}
  14.     mysqlvlib = mysqllib+'.14';
  15.   {$ELSE}
  16.     mysqlvlib = mysqllib+'.12';
  17.   {$ENDIF}
  18. {$ENDIF}
So you first need to install the correct library for connecting to MySQL5.7 so you get the correct libmysqlclient.so.20.0.0.
Or if your server really runs MySQL 5.6 you need to use MySQL56Connection in your program.

obi8

  • New member
  • *
  • Posts: 8
Re: MySQL Connection Error: External:SIGSEGV
« Reply #8 on: February 10, 2017, 01:02:50 pm »
Ok i make a mistake with the version. I have mariadb 10.1.21 with the  library in /usr/lib64/mysql/libmysqlclient.so.18.0.0 .

The Database is on the local machine.
« Last Edit: February 10, 2017, 01:11:49 pm by obi8 »

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: MySQL Connection Error: External:SIGSEGV
« Reply #9 on: February 10, 2017, 01:05:15 pm »
Ok i make a mistake with the version. I have mariadb 10.1.21 with the  library in /usr/lib64/mysql/libmysqlclient.so.18.0.0 .
The Database is on the local machine.
Well, in case you have libmysqlclient.so.18.0.0 you should use TMySQL56Connection and not TMySQL57Connection.

obi8

  • New member
  • *
  • Posts: 8
Re: MySQL Connection Error: External:SIGSEGV
« Reply #10 on: February 10, 2017, 01:11:58 pm »
I change the SQLDBLibraryLoader from 5.7 to 5.6 and the code.
But i get the same error.

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: MySQL Connection Error: External:SIGSEGV
« Reply #11 on: February 10, 2017, 01:17:15 pm »
You could try to see if there is also an normal exception.

Code: Pascal  [Select][+][-]
  1. try
  2.   Open;
  3. except
  4.   on E: Exception do
  5.     Showmessage('Error ' + E.Message);
  6. end;

If that still gives the external SIGSEGV then you might want to run it outside of the Lazarus IDE (or use Run > Run without Debugger). The external SIGSEGV probably comes from GDB debugger. Maybe running it without it will provide more useful information.

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: MySQL Connection Error: External:SIGSEGV
« Reply #12 on: February 10, 2017, 01:19:21 pm »
Another idea. Because you say the error is on the with line....
Is DataModule1.MySQL57Connection1 really initialized.
Try this before the with...
Code: Pascal  [Select][+][-]
  1. if not assigned(DataModule1) then Showmessage('Datamodule1 is not ready');

If all fails you need to create a very small test-project and share it here.

obi8

  • New member
  • *
  • Posts: 8
Re: MySQL Connection Error: External:SIGSEGV
« Reply #13 on: February 10, 2017, 02:38:34 pm »
I get "Datamodule1 is not ready".

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: MySQL Connection Error: External:SIGSEGV
« Reply #14 on: February 10, 2017, 02:41:26 pm »
I get "Datamodule1 is not ready".
Then, your global variable object Datamodule1 isn't yet created.
If Datamodule is a normal datamodule you added via Lazarus, it should be added in the automatically created forms/modules.

Could you check Project > Project Options under Project Options you have Forms.
Under Auto-create forms your should have your form and the DataModule1.
Is that DataModule1 the first, above your own form?
If not, move it up, above your form.
After that you should not get the Error-message anymore.

(Your problem could be that Form1.FormCreate is executed before the whole DataModule1 is created. In which case you get the SIGSEGV. Moving DataModule1 above Form1, you make sure DataModule1 exists before the Form1.FormCreate is executed.)
« Last Edit: February 10, 2017, 02:43:44 pm by rvk »

 

TinyPortal © 2005-2018