Lazarus

Programming => Databases => Topic started by: Stag76 on October 15, 2019, 04:58:24 am

Title: Connecting to SQL Server
Post by: Stag76 on October 15, 2019, 04:58:24 am
I'm developing an application that connects to a SQL Server, using a ZEOS tZConnection.
This works fine connecting to a (Local) SQLServer/DataBase, but I cannot get it to connect to
a Server on another machine, giving OSError 0053 - SQL Server does not exist or Network Access Denied.
I can connect to the remote Server using SSMS.

Does anybody have an example of the tZConnection.Properties required.

I'm using Lazarus 1.0.14, ZEOS 7.1.2(Stable), and SQLServer 2014.
Title: Re: Connecting to SQL Server
Post by: paweld on October 15, 2019, 05:37:41 am
install version 7.3 of Zeos and change protocol to OleDB
Title: Re: Connecting to SQL Server
Post by: Stag76 on October 16, 2019, 10:00:24 pm
Thanks for the reply.

Is this a limitation in ZEOS 7.1.2, or am I using it incorrectly.
I thought having the GUI and Data on separate servers would be a common approach, so I was surprised
that I could only connect to to the Local Server.
I'm also using ntwdblib.dll...should I switch to dbLib.dll?

If I install ZEOS 7.3, which Version of Lazarus should I use?

Thanks again.
Title: Re: Connecting to SQL Server
Post by: af0815 on October 17, 2019, 12:35:47 pm
ntwdblib.dll is a very old dll from M$. I am using freetds libraries for win32, win64 and linux (Debian, Raspbian) derivates. It work with Zeos and SqlDB for me, to connect to MS-SQLServer (running on windows and ubuntu)

The actual stable from Lazarus will be ok. (I am using fixes)
Title: Re: Connecting to SQL Server
Post by: Rainbow6 on October 17, 2019, 11:09:15 pm
Hi,

can I ask, what I have to do, to use FreeTDS with Lazarus? I haven’t figured it out yet. Right now I always use ODBC to connect to SQL Server. Whenever I try to use the TMSSQLConnection, I’m getting runtime errors - even if I drop the freetds DLL into the same directory where the EXE resides. This really puzzles me.

I would really appreciate any tip or help - haven’t found anything using Google.

Thanks and kind regards,
Daniel
Title: Re: Connecting to SQL Server
Post by: af0815 on October 18, 2019, 12:03:35 pm
I always create the connection by code, not by Designer, to set the correct lib.
This sample works for SQLdb. For Zeos you can use nearly the same functionallity. At windows the dll resides in the same dir like the main exe. On Linux it depends on the linux system.

Code: Pascal  [Select][+][-]
  1. procedure TDMSql.DataModuleCreate(Sender: TObject);
  2. begin
  3.   {$ifdef SQLDebug}DebugLn({$I %FILE%} + '->' +{$I %CURRENTROUTINE%} +' start');{$endif}
  4.   try
  5.        // Have to be before creation of the connection
  6.      {$ifdef InLinux}
  7.        {$ifdef RasPi}
  8.        {$ifdef SQLDebug}DebugLn({$I %FILE%} + '->' +{$I %CURRENTROUTINE%} +'Using RasPi Connection');{$endif}
  9.          DBLibLibraryName := 'libsybdb.so.5';
  10.        {$else}
  11.        {$ifdef SQLDebug}DebugLn({$I %FILE%} + '->' +{$I %CURRENTROUTINE%} +'Using Linux X64 Connection');{$endif}
  12.          DBLibLibraryName := '/usr/lib/x86_64-linux-gnu/libsybdb.so.5.0.0';
  13.        {$endif}
  14.        {$else}
  15.        {$ifdef SQLDebug}DebugLn({$I %FILE%} + '->' +{$I %CURRENTROUTINE%} +'Using Windows Connection');{$endif}
  16.          DBLibLibraryName := 'sybdb';
  17.       {$endif}
  18.      {$ifdef SQLDebug}DebugLn({$I %FILE%} + '->' +{$I %CURRENTROUTINE%} +'TDMSQLCon -> DBLibLibraryName = ' + DBLibLibraryName);{$endif}
  19.      SQLCon := TMSSQLConnection.Create(self);
  20.      // Mssql
  21.      SQLTransaction:= TSQLTransaction.Create(SQLCon);
  22.      SQLCon.Transaction := SQLTransaction;
  23.      SQLCon.CharSet:= 'UTF8';
  24.      SQLCon.Options:=[scoApplyUpdatesChecksRowsAffected];
  25.      // common part
  26.      SQLCon.UserName := coUser;
  27.      SQLCon.Password := coPW;
  28.   finally
  29.      //
  30.   end;
  31.   {$ifdef SQLDebug}DebugLn({$I %FILE%} + '->' +{$I %CURRENTROUTINE%} +' end');{$endif}
  32. end;
  33.  
TinyPortal © 2005-2018