[Lazarus] Simple MSSQL database connection fails from Lazarus 1.6/FPC 3.0.0...

Bo Berglund bo.berglund at gmail.com
Tue Feb 23 14:14:56 CET 2016


I just installed Lazarus release 1.6 from svn sources and it seemed
OK. I have FPC 3.0.0 also installed from svn sources.
All is installed on a Raspbian Jessie system on a Raspberry Pi2
device.

So I used Lazarus to make a database connection test to see if it is
possible to connect to an MSSQL database using Lazarus/FPC.
A very simple test consisting of two buttons, a shape to signal
success and the TMSSQLConnection component like this:

unit FormMain;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls,
  ExtCtrls, mssqlconn;

type

  { TForm1 }

  TForm1 = class(TForm)
    btnOpenDB: TButton;
    btnCloseDB: TButton;
    connDB: TMSSQLConnection;
    shpDbLed: TShape;
    procedure btnCloseDBClick(Sender: TObject);
    procedure btnOpenDBClick(Sender: TObject);
  private
    procedure CloseConnection;
    function OpenConnection: boolean;
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.btnOpenDBClick(Sender: TObject);
begin
  if OpenConnection then
     shpDBLed.Brush.Color:= clLime
  else
    shpDBLed.Brush.Color:= clRed;
end;

procedure TForm1.btnCloseDBClick(Sender: TObject);
begin
  CloseConnection;
  shpDBLed.Brush.Color:= clRed;
end;

procedure TForm1.CloseConnection;
begin
  if connDB.Connected then
     connDB.Close(true);
end;

function TForm1.OpenConnection: boolean;
begin
  try
    Result := false;
    if connDB.Connected then
       CloseConnection;

    connDB.LoginPrompt := false;
    connDB.DatabaseName:= 'MYDATABASE';
    connDB.HostName:= 'MYDBSERVER';
    connDB.UserName:= '<dbuser>';
    connDB.Password:= '<passwd>';
    connDB.Open;
    Result := connDB.Connected;
  except
  end;

end;
end.

When I click the btnOpenDB to run the OpenConnection method an
exception is generated:

Debugger Exception Notification
Project DBTest raised exception class 'EInOutError' with message:
Can not load DB-Lib client library "libsybdb.so". Check your
installation.
Success

At address 2FCBE4
   [Break]   [Continue]

I thought that since there was a SQLDb component TMSSQLConnection
available it would be possible to connect to a database server running
MSSQL, but apparently something is missing here.
THe message talks about libsybdb.so, what is that and do I need some
other stuff to go with Lazarus to do database work?


-- 
Bo Berglund
Developer in Sweden





More information about the Lazarus mailing list