how to connect msSql server version 16 lazarus / 16-Databases ---------------------------------------------------------------------- rcmz · 2024-07-08 18:22 hi, What component do you recommend to connect to msSql server version 16? some samples are wellcome. TIA Ramiro ---------------------------------------------------------------------- Handoko · 2024-07-08 18:31 Have you tried mssqlconn or Zeos? https://wiki.lazarus.freepascal.org/mssqlconn https://wiki.freepascal.org/Zeos_tutorial ---------------------------------------------------------------------- toby · 2024-07-08 18:39 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 · 2024-07-09 09:04 @rcmz: as @handoko wrote: Zeos or SqlDB. In the attachment is a simple example using Zeos components - the MSSQL OleDB driver must be installed. ---------------------------------------------------------------------- Zvoni · 2024-07-09 09:22 Quote from: toby on July 08, 2024, 08:39:47 pmhi since you appear to be at the very beginning of you sql journey ..... Whatevery gave you that impression? Quoteyou 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 ---------------------------------------------------------------------- toby · 2024-07-09 17:17 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 ---------------------------------------------------------------------- dsiders · 2024-07-09 17:23 Quote from: toby on July 09, 2024, 07:17:34 pmignore list - what is this irc in the 1980's didn't you mean to say *plonk* Absolutely. *PLONK* ---------------------------------------------------------------------- rcmz · 2024-07-09 23:05 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 · 2024-07-09 23:43 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program mssql; {$APPTYPE CONSOLE} uses  SysUtils, ZConnection, ZDataset; // add zcomponent to Lazarus' Project Inspector requirements const  DBName = 'YOUR_DB_NAME';  DBHost = 'YOUR_DB_HOST';  DBUser = 'YOUR_DB_USERNAME';  DBPassword = 'YOUR_DB_PASSWORD'; var  ZCMSSQL: TZConnection;  ZQuery: TZQuery; begin  try    ZCMSSQL := TZConnection.Create(nil);    ZCMSSQL.ClientCodepage := 'UTF-8';    ZCMSSQL.Catalog := DBName;    ZCMSSQL.Database := DBName;    ZCMSSQL.Protocol := 'FreeTDS_MsSQL>=2005';    ZCMSSQL.User := DBUser;    ZCMSSQL.Password := DBPassword;    ZCMSSQL.HostName := DBHost;    ZCMSSQL.LoginPrompt := False;    try      ZCMSSQL.Connect;    except    WriteLn('Error connecting to ''' + DBName + ''' (' + DBHost + ').');    end;     if not ZCMSSQL.Connected then      Exit;     ZQuery := TZQuery.Create(nil);    try      ZQuery.Connection := ZCMSSQL;     ZQuery.SQL.Text :=        'select top 10 "your_field_name" ' +      'from "your_table" ' +        'where "field_name" > :your_field_name ' +        'order by 1 desc';      ZQuery.ParamByName('your_field_name').AsInteger := 10;      ZQuery.Open;       While not ZQuery.EOF do      begin        WriteLn(ZQuery.Fields[0].AsString);        ZQuery.Next;      end;    finally      ZQuery.Free;    end;  finally    ZCMSSQL.Disconnect;    ZCMSSQL.Free;  end;end. ---------------------------------------------------------------------- rcmz · 2024-07-10 02:15 Thx!!! I will give it a try Ramiro