[Lazarus] Porting Delphi (2007/XE5) application, how to handle ADODB?

Bo Berglund bo.berglund at gmail.com
Fri Feb 10 12:35:58 CET 2023

On Mon, 23 Jan 2023 09:59:14 +0100 (CET), Michael Van Canneyt via lazarus
<lazarus at lists.lazarus-ide.org> wrote:

>On Mon, 23 Jan 2023, Bo Berglund via lazarus wrote:
>> I have a number of "older" applications developed on Windows using
>> Delphi7-2007-XE5, which use ADODB for database accesses.
>> The database is Microsoft SQLSERVER.
>> Now I no longer have the old Borland software installed (issues with Windows 10
>> etc) so I want to port the projects to FPC/Lazarus.
>> I have ported some other non-database applications which (with some effort)
>> seems to have worked out OK.
>> Now I am facing the challenge of doing it on an adodb database enabled
>> application and I would like to know if there is some "compatible" way of doing
>> it, which is described somewhere?
>You need to use SQLDB, and the TMSSQLConnection.
>See https://wiki.freepascal.org/SQLdb_Tutorial1 for a simple explanation.
>The page https://wiki.freepascal.org/SQLdb_Package also contains some explanations
>for setup.
>There are some other pages in the wiki.
>A more in-depth explanation is in the lazarus book.
>Or you can look at
>several articles discuss SQLDB, in particular:
>That should be enough to get you started.


Almost there but not quite...
I am using Lazarus 2.2.4 with fpc 3.2.2 on a Windows 10 box.

The application seems to have been converted pretty well using the Lazarus
Delphi Conversion function to migrate from Delphi with some extra defines
needing adjustments. But these have been minor considering the size of the

But the ADODB conversion is now halted on the TSqlQuery and TMSSQLConnection
items which operate so differently from ADODB...

I added this in uses:

  mssqlconn, //Had to add this in order to use TMSSQLConnection

This made the code pass the defines of the objects:

  TAppDbHandler = class
    FConn: TMSSQLConnection;  // TADOConnection;
    FQuery: TSQLQuery;        // TADOQuery;
    FUserPassword: string;

But next I get a lot of errors because of the differences between this and the
Delphi ADODB we used before.

I got lost here...

constructor TAppDbHandler.Create;
  FConn := TMSSQLConnection.Create(NIL);   //was: TADOConnection.Create(NIL);
  FQuery := TSQLQuery.Create(NIL); //was: TADOQuery.Create(NIL);
  FQuery.Connection := FConn; //<== Triggers an error
  FDatabaseServer :=
  FDatabase :=
  FConnString := 'Provider=SQLOLEDB.1;Persist Security Info=False;' +
                 'Network Library=DBMSSOCN;Data Source=' + FDatabaseServer + ';'
                 'Initial Catalog=' + FDatabase;
  FDbUser := '****';
  FDbPassword := '****';

Is there some example which does not use component drag-drop and properties
settings in the GUI but does all of it in code towards MSSQLserver?

That would probably help in setting up the database functions properly.

Bo Berglund
Developer in Sweden

More information about the lazarus mailing list