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

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Bo Berglund
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


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

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

Marcos Douglas
On Tue, Feb 23, 2016 at 10:14 AM, Bo Berglund <[hidden email]> wrote:
> 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

Maybe this will help you.
http://wiki.freepascal.org/mssqlconn

Marcos Douglas

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

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

Michael Van Canneyt
In reply to this post by Bo Berglund


On Tue, 23 Feb 2016, Bo Berglund wrote:

> 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.
>
>
> 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?

This is the FreeTDS library, an open source library that is needed to
connect to SQL Server. FPC's SQLDB TMSSQLConnection implementation uses
this library.

You simply need to install it on your system (if it is available).
Install also the -dev version of the package.

Michael.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

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

Bo Berglund
On Tue, 23 Feb 2016 15:08:09 +0100 (CET), Michael Van Canneyt
<[hidden email]> wrote:

>This is the FreeTDS library, an open source library that is needed to
>connect to SQL Server. FPC's SQLDB TMSSQLConnection implementation uses
>this library.
>
>You simply need to install it on your system (if it is available).
>Install also the -dev version of the package.
>
Fonnd their homepage here:
http://www.freetds.org/

It did not really give much installation advice so I googled
"installing freetds in Raspbian Jessie" instead and found some hints
that lead to:
sudo apt-get install freetds-dev
This command succeeeds on my system.
But this does not:
sudo apt-get install freetds

Since the -dev was an "also" package, how can I get the basic freetds
package? Or maybe it is not really needed?

My test program shown above now runs to a green panel!
Time to expand it to see if it is actually working...
Will try to run a query and see the result. :)


--
Bo Berglund
Developer in Sweden


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

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

leledumbo
Administrator
> Since the -dev was an "also" package, how can I get the basic freetds
> package? Or maybe it is not really needed?

Normally if you install the -dev package, the runtime one is also installed since it's a dependency. Try `apt-cache search freetds` to see what related packages are available.
Reply | Threaded
Open this post in threaded view
|

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

Bo Berglund
On Tue, 23 Feb 2016 10:49:47 -0700 (MST), leledumbo
<[hidden email]> wrote:

>> Since the -dev was an "also" package, how can I get the basic freetds
>> package? Or maybe it is not really needed?
>
>Normally if you install the -dev package, the runtime one is also installed
>since it's a dependency. Try `apt-cache search freetds` to see what related
>packages are available.
>
THis is the result:

pi@rpi2-jessie2:~ $ sudo apt-cache search freetds
freetds-bin - FreeTDS command-line utilities
freetds-common - configuration files for FreeTDS SQL client libraries
freetds-dev - MS SQL and Sybase client library (static libs and
headers)
libct4 - libraries for connecting to MS SQL and Sybase SQL servers
libdbd-freetds - Freetds database server driver for libdbi
libqt4-sql-tds - Qt 4 FreeTDS database driver
libqt5sql5-tds - Qt 5 FreeTDS database driver
libsybdb5 - libraries for connecting to MS SQL and Sybase SQL servers
sqsh - commandline SQL client for MS SQL and Sybase servers
tdsodbc - ODBC driver for connecting to MS SQL and Sybase SQL servers

Seems like there are -bin, -common along with -dev...

Now heading for some SQL queries using the established connection!


--
Bo Berglund
Developer in Sweden


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus