Recent

Author Topic: how to connect msSql server version 16  (Read 1041 times)

rcmz

  • Full Member
  • ***
  • Posts: 133
how to connect msSql server version 16
« on: July 08, 2024, 08:22:26 pm »
hi,

What component do you recommend to connect to msSql server version 16?

some samples are wellcome.

TIA
Ramiro

Handoko

  • Hero Member
  • *****
  • Posts: 5289
  • My goal: build my own game engine using Lazarus
« Last Edit: July 08, 2024, 08:34:36 pm by Handoko »

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: how to connect msSql server version 16
« Reply #2 on: July 08, 2024, 08:39:47 pm »
hi

since you appear to be at the very beginning of you sql journey you should immediately switch to mariadb - in term of reliability and speed and security it runs rings around ms nonsense

you will get tremendous already written code for mariadb/mysql in the fpc examples and this forum has great code in it's history to

paweld

  • Hero Member
  • *****
  • Posts: 1179
Re: how to connect msSql server version 16
« Reply #3 on: July 09, 2024, 11:04:31 am »
@rcmz: as @handoko wrote: Zeos or SqlDB.
In the attachment is a simple example using Zeos components - the MSSQL OleDB driver must be installed.
Best regards / Pozdrawiam
paweld

Zvoni

  • Hero Member
  • *****
  • Posts: 2607
Re: how to connect msSql server version 16
« Reply #4 on: July 09, 2024, 11:22:06 am »
hi

since you appear to be at the very beginning of you sql journey .....
Whatevery gave you that impression?

Quote
you should immediately switch to mariadb - in term of reliability and speed and security it runs rings around ms nonsense

you will get tremendous already written code for mariadb/mysql in the fpc examples and this forum has great code in it's history to
What utter nonsense.
Do you know, if his requirements are predefined? Like working in a company, where he is required to write a tool accessing there Database-Server, which runs MS SQL?.

I do work for a company, which runs a DB2 on an IBM iSeries.
If i would post a question like "Which component/classes to use to access DB2?" and i would see an answer like yours, you would go straight to my ignore list.

So please refrain from non-answers.
It's just polluting the forum
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: how to connect msSql server version 16
« Reply #5 on: July 09, 2024, 07:17:34 pm »
rcmz
check out sqlite too - easier to install then mariadb/mysql



Zvoni
how about his statement?

'What component do you recommend to connect to msSql server version 16?'

but then again he could already be connecting and working on the server but wants to know what you recommend he use so he can redo all his work based on what you say

'Do you know, if his requirements are predefined? Like working in a company, where he is required to write a tool accessing there Database-Server, which runs MS SQL?.'

do you think his boss of your imaginary company would be happy knowing the guy he hired to make an advanced tool to use on his commecial database - needs to find out how to even connect to the server?

ignore list - what is this irc in the 1980's
didn't you mean to say *plonk*

your whole reply sounds like an unconscious confession and makes me think of the guy who lied on his resume and got hired to do db2 programming and then went to programming forums to supplement his lack of knowledge and keep up the sham - his fellow programmers got tired of his crappy code and got him fired

your signature sounds a bit pscho maoist too
« Last Edit: July 09, 2024, 07:42:40 pm by toby »

dsiders

  • Hero Member
  • *****
  • Posts: 1206
Re: how to connect msSql server version 16
« Reply #6 on: July 09, 2024, 07:23:24 pm »
ignore list - what is this irc in the 1980's
didn't you mean to say *plonk*

Absolutely. *PLONK*
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

rcmz

  • Full Member
  • ***
  • Posts: 133
Re: how to connect msSql server version 16
« Reply #7 on: July 10, 2024, 01:05:53 am »
Hi,

thx for your replys I will give them a try.

I use Firebird since 2007, have also worked with MySql, Oracle Progres, PostgresSql and msSql server but with Delphi.

Since 2018 I been moving my work to Lazarus using only Firebird with the ibDac component of devart.

I have a client that works exclusively with msSql server and until this time I had no use to connect to msSql server. There is a component from devart to connect to msSql but my client is not willing to pay the price.

TIA
Ramiro

dseligo

  • Hero Member
  • *****
  • Posts: 1334
Re: how to connect msSql server version 16
« Reply #8 on: July 10, 2024, 01:43:46 am »
I use ZEOSdbo components to connect to MSSQL.

Below is example how to connect from code, but of course you can put components to forms or data modules too (and set them in Object inspector). P.S.: ZEOSdbo is in Online Package Manager, but I still use 7.2.14 version, so code below maybe needs little adjusting to work with newest version.

Beside this, you'll also need library such as https://www.freetds.org/.

Code: Pascal  [Select][+][-]
  1. program mssql;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils, ZConnection, ZDataset; // add zcomponent to Lazarus' Project Inspector requirements
  7.  
  8. const
  9.   DBName = 'YOUR_DB_NAME';
  10.   DBHost = 'YOUR_DB_HOST';
  11.   DBUser = 'YOUR_DB_USERNAME';
  12.   DBPassword = 'YOUR_DB_PASSWORD';
  13.  
  14. var
  15.   ZCMSSQL: TZConnection;
  16.   ZQuery: TZQuery;
  17.  
  18. begin
  19.   try
  20.     ZCMSSQL := TZConnection.Create(nil);
  21.     ZCMSSQL.ClientCodepage := 'UTF-8';
  22.     ZCMSSQL.Catalog := DBName;
  23.     ZCMSSQL.Database := DBName;
  24.     ZCMSSQL.Protocol := 'FreeTDS_MsSQL>=2005';
  25.     ZCMSSQL.User := DBUser;
  26.     ZCMSSQL.Password := DBPassword;
  27.     ZCMSSQL.HostName := DBHost;
  28.     ZCMSSQL.LoginPrompt := False;
  29.     try
  30.       ZCMSSQL.Connect;
  31.     except
  32.       WriteLn('Error connecting to ''' + DBName + ''' (' + DBHost + ').');
  33.     end;
  34.  
  35.     if not ZCMSSQL.Connected then
  36.       Exit;
  37.  
  38.     ZQuery := TZQuery.Create(nil);
  39.     try
  40.       ZQuery.Connection := ZCMSSQL;
  41.  
  42.       ZQuery.SQL.Text :=
  43.         'select top 10 "your_field_name" ' +
  44.         'from "your_table" ' +
  45.         'where "field_name" > :your_field_name ' +
  46.         'order by 1 desc';
  47.       ZQuery.ParamByName('your_field_name').AsInteger := 10;
  48.       ZQuery.Open;
  49.  
  50.       While not ZQuery.EOF do
  51.       begin
  52.         WriteLn(ZQuery.Fields[0].AsString);
  53.         ZQuery.Next;
  54.       end;
  55.     finally
  56.       ZQuery.Free;
  57.     end;
  58.   finally
  59.     ZCMSSQL.Disconnect;
  60.     ZCMSSQL.Free;
  61.   end;
  62. end.
« Last Edit: July 10, 2024, 01:46:43 am by dseligo »

rcmz

  • Full Member
  • ***
  • Posts: 133
Re: how to connect msSql server version 16
« Reply #9 on: July 10, 2024, 04:15:02 am »
Thx!!!

I will give it a try

Ramiro


 

TinyPortal © 2005-2018