Azure sql database will not connect lazarus / 16-Databases ---------------------------------------------------------------------- wpflum · 2024-04-12 16:42 I'm trying to use an Azure SQL database and not matter what i cannot get my program to connect to it.  I've tried using different connectors and the connection string that Azure shows me in the Portal to connect but keep getting an error 20002.  Nothing I search for seems to show me a package that will work. Right now just adding a connector to a form and trying to enable it is as far as I get.  Any direction toward a solution would be appreciated. ---------------------------------------------------------------------- paweld · 2024-04-12 17:32 I use SDAC components from Devart:  https://www.devart.com/sdac/ They are paid but work very well with MSSQL. They also connect to Azure SQL without a problem - there is a trial version available on the site, so you can check it out for yourself. But I also think you should connect to Azure SQL using ZEOS components - I'll try to check it tomorrow and get back with an update ---------------------------------------------------------------------- wpflum · 2024-04-12 17:45 I tried to install the trial version but can't figure out how, when I try adding the package it tells me it can not find MTSCall.pas.  I'll look into the ZEOS option. ---------------------------------------------------------------------- paweld · 2024-04-12 17:58 The trial version works only on lazarus 3.0 with fpc 3.2.2. You download the archive, unzip it so that the path has no spaces or characters other than ASCII, then in lazarus click the "Package > Open package file" menu and select the file "sdac\packages\dclsdac10.lpk" and click "Install" - important: do not compile the package! ---------------------------------------------------------------------- paweld · 2024-04-13 05:33 Ok, I checked ZEOS and it also works without problems. I use ZEOS 8: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 procedure TForm1.Button1Click(Sender: TObject);var  server, db, login, pass: String;begin  server := 'myAzureServerName.database.windows.net';  db := 'myDatabaseName';  login := 'myLogin';  pass := 'myPassword';  //zeos  ZConnection1.Protocol := 'OleDB';  ZConnection1.HostName := server;  ZConnection1.User := login;  ZConnection1.Password := pass;  ZConnection1.Database := Format('Provider=MSOLEDBSQL;Data Source=%s;Initial Catalog=%s;Authentication=SqlPassword;User ID=%s;Password=%s;', [server, db, login, pass]);  ZConnection1.Connect; end; ---------------------------------------------------------------------- wpflum · 2024-04-15 19:04 Thanks, that works.  Now I just have to remember how I did the rest of the program after not touching it for a year ---------------------------------------------------------------------- wpflum · 2024-04-16 14:04 Stupid question, I'd like to be able to use the IDE to play with the connection but nothing I do allows me to check the Connected box and not get an error.  Doing it in code seems to work but trying to add in the same options isn't working, so I'm missing something.  Any idea? ---------------------------------------------------------------------- paweld · 2024-04-17 05:41 I suspect that the firewall is blocking the connection to the server. You need to add an exception on the firewall that excludes blocking Lazarus. ---------------------------------------------------------------------- wpflum · 2024-04-17 16:21 The program is working but now I have another issue, I'm getting an error on another PC when I try and run the exe, 'Class not registered', it works on the machine it was compiled on.  I'm guessing it's related to the ZEOS library but what do i do to register it? ---------------------------------------------------------------------- paweld · 2024-04-17 17:05 The "Microsoft OLE DB Driver for SQL Server" must be installed on the computer: https://learn.microsoft.com/en- us/sql/connect/oledb/download-oledb-driver-for-sql-server?view=sql- server-ver16 ---------------------------------------------------------------------- wpflum · 2024-04-17 17:15 Installed it and rebooted and still the same error.  I even installed the VC_redist.x64 just in case since it was mentioned on the Microsoft OLE DB Driver for SQL Server page ---------------------------------------------------------------------- wpflum · 2024-04-17 17:56 This is weird,, I tried installing Lazarus and Zeos on the second computer and then compiled the program and still get the class error. ---------------------------------------------------------------------- wpflum · 2024-04-17 18:00 Just tried another PC and get the same error.  If I compile a simple test program with just a button that closes the form it runs on both PCs. ---------------------------------------------------------------------- paweld · 2024-04-17 18:06 Did you install a driver that is compatible with the program, i.e. if you compiled a 32-bit program, the driver must also be 32-bit. Also provide information about your operating system - I will try to check tomorrow ---------------------------------------------------------------------- wpflum · 2024-04-17 18:14 Both PCs are Windows 11 64bit and the last one I tried was a Windows 10 64 bit, the 64 bit driver is what I installed.  I also narrowed it down to the Zeos library as if I add a TZConnection to the test program and have it try and connect to the database I get the same error as the big program. I'm sure I'm doing something stupid. ---------------------------------------------------------------------- dseligo · 2024-04-17 20:15 Quote from: wpflum on April 17, 2024, 08:14:05 pmBoth PCs are Windows 11 64bit and the last one I tried was a Windows 10 64 bit, the 64 bit driver is what I installed. Is your program also 64 bit? ---------------------------------------------------------------------- paweld · 2024-04-18 05:24 Hi, You need to install the previous version of msoledb: https://www.microsoft.com/en-us/download/details.aspx?id=56730 I misled a bit earlier, because the bitness of the driver is supposed to match the bitness of the operating system and not the application. ---------------------------------------------------------------------- wpflum · 2024-04-18 12:18 That did it!!   Thanks, I was getting a bit worried because I needed this fairly soon. Thanks again.