dblib.dll error - MS SQL Express lazarus / 16-Databases ---------------------------------------------------------------------- ap3000 · 2024-04-26 13:28 Hello I can't get the dblib.dll found/loaden in a small test console app. I have downloaded the dblib.dll from here: http://downloads.freepascal.org/fpc/contrib/windows/. I have tried nearly every single one of them but every time I get the error: Can not load DB-Lib client library "dblib.dll". Check your installation. The specified module could not be found. I have the dblib in the folder of the executable. Hier my code: 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 project1; uses  Classes,  SysUtils,  MSSQLConn,  SQLDB; var  AConnection: TMSSQLConnection;  Atransaction: TSQLTransaction;  AQuery: TSQLQuery; begin  AConnection := TMSSQLConnection.Create(nil);  Atransaction := TSQLTransaction.Create(nil);  AQuery := TSQLQuery.Create(nil);   try  try      AConnection.HostName := 'localhost\SQLEXPRESS';      AConnection.Connected := False;      AConnection.LoginPrompt := False;      AConnection.DatabaseName := 'ContactDB';       Atransaction.DataBase := AConnection;      AConnection.Transaction := Atransaction;      AQuery.DataBase := AConnection;       AConnection.Open;       AQuery.SQL.Text := 'SELECT * FROM ContactDB';      AQuery.Open;       while not AQuery.EOF do      begin        WriteLn(AQuery.FieldByName('FirstName').AsString, ' ',          AQuery.FieldByName('LastName').AsString);      end;    except      on E: Exception do        WriteLn('Error: ' + E.Message);    end;  finally    AConnection.Close();    AQuery.Free;    Atransaction.Free;    AConnection.Free;  end;   ReadLn;end. ---------------------------------------------------------------------- alpine · 2024-04-26 13:37 Check dblib.dll requirements. It is possible that it requires some specific Microsoft Visual C++ Redistributable installed (MSVCRT). ---------------------------------------------------------------------- paweld · 2024-04-26 14:26 To connect to MSSQL, I recommend using the Zeos package with OleDB set as the protocol. Sample (it's for Azure, but you connect to the MSSQL server the same way): https://forum.lazarus.freepascal.org/index.php/t opic,66955.msg514263.html#msg514263 ---------------------------------------------------------------------- NobleStar · 2024-04-26 16:58 I believe you also need the Libiconv.dll file to go along with the dblib.dll. ---------------------------------------------------------------------- Zvoni · 2024-04-26 17:06 And his next error will come at line 34….. ---------------------------------------------------------------------- ap3000 · 2024-04-26 18:35 Oeps..  QuoteAnd his next error will come at line 34….. Quote from: NobleStar on April 26, 2024, 06:58:48 pmI believe you also need the Libiconv.dll file to go along with the dblib.dll. And where do I find the Libiconv.dll? ---------------------------------------------------------------------- cdbc · 2024-04-26 18:54 Hej Anders Har du prøvet den her:https://www.dll-files.com/libiconv.dll.html 1. hit on google... eng: Have you tried this one: ^^^^ Regards Benny ---------------------------------------------------------------------- NobleStar · 2024-04-26 19:04 You got the DBlib.dll and Libiconv.dll should be in the same zip file.  http://downloads.freepascal.org/fpc/contrib/windows/. ---------------------------------------------------------------------- ap3000 · 2024-04-26 20:07 Thanks Now it can find/load the dblib.dll, but now I get this error: Project project1 raised exception class 'EMSSQLDatabaseError' with message: MSSQLConnection1 : Error 20009 : Unable to connect: Adaptive Server is unavailable or does not exist (DESKTOP-N1EKOSK) I have tried Localhost, 127.0.0.1 and its IP address but no result. But I can access de database server in SQL Server Management Studio with the server name DESKTOP-N1EKOSK\SQLEXPRESS I use SQL Server Authentication. What can sill be vrong? ---------------------------------------------------------------------- alpine · 2024-04-26 20:23 QuoteWhat can sill be vrong?Is the IP comm.protocol enabled at the server? Is it the default instance or it is a named one? ---------------------------------------------------------------------- ap3000 · 2024-04-26 20:59 Hi Alpine I'm not sure what you mean by "Is the IP comm.protocol enabled at the server?" I tried to enable the TCP/IP protocol under Server Network Configuration, without result (See image) "Is it the default instance or it is a named one?" It's the only MS SQL Server on this machine. Se the image for how it is running as Windows Service. ---------------------------------------------------------------------- alpine · 2024-04-27 05:02 As you have noticed the TCP/IP can be disabled and I think it is by default. You must enable it. Several MSSQL instances can be installed on a single computer. AFAIK the connection mechanism then differs in order to find on which port to connect with each of them. Additional service is used for the purpose. Only when it is installed as a 'default' instance it is available on a port 1433. The port must be checked into the protocol configuration anyway. But I'm not seasoned DB admin, so please check the corresponding documentation and/or some other (MSSQL) forums. Edit: I have just read on the Micro$oft site that named instances can also be configured on a specific port, you must disable 'TCP Dynamic ports' and check the IPAll section. ---------------------------------------------------------------------- ap3000 · 2024-04-27 10:29 Hi Alpine Thank you for your continuous help, most appreciated. But I don't think that there is something wrong with the server. I just created the same console app in VS C# and it's act as expected. Could it be that I used the wrong client libraries? I downloaded this one "dblib_current.zip" from the server. Or are there any other properties that I have to set - PortNumber or something else (I believe that the server listening on default 1433) Here the C# code data works Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i using System.Data.SqlClient; namespace ConsoleAppMsSqlServer_test; internal class Program{    static void Main(string[] args)    {        string connectionString = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=ContactDB;User ID=ap;Password=Password;";         using (SqlConnection connection = new SqlConnection(connectionString))      {            string query = "SELECT * FROM Contacts";             SqlCommand command = new SqlCommand(query, connection);             connection.Open();             SqlDataReader reader = command.ExecuteReader();             Console.WriteLine("Contacts:");             while (reader.Read())            {                string id = reader["Id"].ToString();                string firstName = reader["FirstName"].ToString();                string lastName = reader["LastName"].ToString();                                 Console.WriteLine($"Id: {id}, First name: {firstName}, Last name: {lastName}");            }             reader.Close();        }    }} ---------------------------------------------------------------------- dseligo · 2024-04-27 12:16 Quote from: ap3000 on April 27, 2024, 12:29:51 pmBut I don't think that there is something wrong with the server. I just created the same console app in VS C# and it's act as expected. Could it be that I used the wrong client libraries? I downloaded this one "dblib_current.zip" from the server. Or are there any other properties that I have to set - PortNumber or something else (I believe that the server listening on default 1433) Can you try to with https://www.heidisql.com/ (it is database administration tool which can connect to several SQL servers)? Set network type to 'Microsoft SQL Server (TCP/IP)', library to SQLOLEDB, hostname, user, password and database (I attached how one of entries looks like). If you can connect, then the server side is OK. Also check reply #2 (although I use both Zeos and SQLdb components to connect to MSSQL). ---------------------------------------------------------------------- ap3000 · 2024-04-27 13:15 Yes I could connect, but first after installing de OLEdb driver. But I still get the same error message: Error: TMSSQLConnection : Error 20009 : Unable to connect: Adaptive Server is unavailable or does not exist (DESKTOP-N1EKOSK) But why should we use OLEdb driver? The dblib.dll is a SQL server client library - Of not? ---------------------------------------------------------------------- alpine · 2024-04-27 14:14 QuoteOr are there any other properties that I have to set - PortNumber or something else (I believe that the server listening on default 1433) You can check into the Configuration Manager (as the attached picture in reply #10), the "IP Addresses" tab. You can see the output of: Code: [Select]netstat -anLook for a listening socket on 0.0.0.0:1433 Again: Are you sure you have the appropriate MSVCRT installed as is it shown on the second attachment? (working test proj on my laptop) Attached is the version info of the libiconv2.dll. Unfortunately dblib.dll doesn't have such info. ---------------------------------------------------------------------- ap3000 · 2024-04-27 18:41 Thanks, Alpine Indeed, I don't get something listening on port 1433 when I do a netstat -an. When I run Dependency Walker I see MSVCR80.DLL but I also see some errors, but I have no clue what they mean. I included the dblib.dwi file from Dependency Walker. I hope someone can make something of it. I also installed SQL Express in a new Virtual Machine and there I got the same results - No listener on port 1433 and the same error messages in Dependency Walker. Oeps the dblib.dwi file is to big, so her alink: https://www.dropbox.c om/scl/fi/pu2e6hnlg5fs827kg9fc6/dblib.dwi?rlkey=cmvfft69wkftddj5s51j5h fo7&st=zngkkvlh&dl=0 ---------------------------------------------------------------------- alpine · 2024-04-27 19:01 Check the attached picture. TCP Dynamic Ports must be empty. TCP Port must be 1433 (or other, as long as you specify it correctly into the client connection) You must also specify it as an exception into the firewall. Hope you won't make it open in Internet, you'll get immediately flooded then. ---------------------------------------------------------------------- ap3000 · 2024-04-27 19:29 No - still same result  But I don't understand why my C# console app is working and the Pascal doesn't. I then think that the SQL server is OK. But that of the TMSSQLConnection needs some configuration that I don't know about or indeed that the SQL client driver need some more dll's ---------------------------------------------------------------------- alpine · 2024-04-27 19:43 Did you restart the server after changing the configuration? You have to direct your effort into TCP/IP Server configuration until netstat -an shows that there is a service listening at 0.0.0.0:1433. Until then all your connection attempts will fail. ---------------------------------------------------------------------- ap3000 · 2024-04-27 21:25 Yes, I restarted the server and now I get a service listening on 0.0.0.0:1433. But still the error: Error: TMSSQLConnection : Error 20009 : Unable to connect: Adaptive Server is unavailable or does not exist (DESKTOP-N1EKOSK) ---------------------------------------------------------------------- alpine · 2024-04-27 21:31 Try to use an IP address instead of a name. In case of the local machine use 127.0.0.1 (local loopback). ---------------------------------------------------------------------- Zvoni · 2024-04-28 06:09 Has anyone ckecked 32-bit vs. 64 bit? ---------------------------------------------------------------------- ap3000 · 2024-04-28 10:35 Yes, I have tried IP-Adress, 127.0.0.1, 0.0.0.0 and the IP-Adress of the computer itself. And I have tried all kinds of combinations of 32 vs 64-bit. I have tried older versions of dblib.dll. I start to ask myself if I'm the only one who wants to use MS SQL Express in combination with FreePascal/Lazarus. ---------------------------------------------------------------------- alpine · 2024-04-28 11:04 Quote from: ap3000 on April 28, 2024, 12:35:34 pmYes, I have tried IP- Adress, 127.0.0.1, 0.0.0.0 and the IP-Adress of the computer itself. And I have tried all kinds of combinations of 32 vs 64-bit. I have tried older versions of dblib.dll. I start to ask myself if I'm the only one who wants to use MS SQL Express in combination with FreePascal/Lazarus. I'm using it, it is not because I want it, but I must to. My Lazarus apps are 32-bit. I have found the exact dblib.dll+libiconv2.dll that works for me, all MSSQLs are installed as default instances (please, consult M$ site for the meaning of 'default instance'). The installation troubles that I usually have are: Correct version of MSVCRT missing. MSSQL was installed with the default collation, (then masterdb must be rebuilt with the exact collation needed). Firewall doesn't allow client connections. ---------------------------------------------------------------------- ap3000 · 2024-04-28 20:47 Hi Alpine Yes, MS SQL Express is installed as the default instance and I have the 0.0.0.0:1433 from netstat -an. But I see a difference between your and my screenshot of the Dependency Walker. In my screenshot some of the Icons are red, yours is not. Could there be a reason? You write "I have found the exact dblib.dll+libiconv2.dll". What are those files and where can I get them? I'm not sure how I can find out if I have the Correct version of MSVCRT? ---------------------------------------------------------------------- alpine · 2024-04-28 22:11 Quote from: ap3000 on April 28, 2024, 10:47:22 pmHi Alpine Yes, MS SQL Express is installed as the default instance and I have the 0.0.0.0:1433 from netstat -an. But I see a difference between your and my screenshot of the Dependency Walker. In my screenshot some of the Icons are red, yours is not. Could there be a reason? Not sure. As I said, mine is 32-bit. Yours - 64. I don't think that is the main problem, but you must always use libraries with the same bitness as your app. Otherwise you'll get the error as in the original post. Quote from: ap3000 on April 28, 2024, 10:47:22 pmYou write "I have found the exact dblib.dll+libiconv2.dll". What are those files and where can I get them? http://downloads.freepascal.org/fpc/contrib/windows/ (your original post) There are several versions in zip files. Into the zip files are all dlls for both 32 and 64 bit. Quote from: ap3000 on April 28, 2024, 10:47:22 pmI'm not sure how I can find out if I have the Correct version of MSVCRT? https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc- redist?view=msvc-170 (show more link) I believe you have it, since in the dependency walker it is not red (MSVCR80.DLL). Of course, you must install for the same bitness (32 or 64) as your app and your dblib.dll, libicon2.dll. I'm a little concerned about: 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 AConnection.HostName := 'localhost\SQLEXPRESS'; I think it should be just: 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 AConnection.HostName := 'localhost';for the default instance. My (default) instance name is MSSQLSERVER (seen in my reply #17). Yours: SQLEXPRESS (in your reply #10). Quote from https://learn.microsoft.com/en-us/sql/sql- server/install/instance-configuration?view=sql-server-ver16: QuoteAn instance is either the default instance or a named instance. The default instance name is MSSQLSERVER. The default name doesn't require a client to specify the name of the instance to make a connection. A named instance is determined by the user during Setup. You can install SQL Server as a named instance without installing the default instance first. Only one installation of SQL Server, no matter the version, can be the default instance at one time. I'm guessing that might be a problem, MS SQL is full of such a nasty particularities. ---------------------------------------------------------------------- ap3000 · 2024-04-30 19:24 Problem solved  Hi Alpine, You nailed it - HostName needs to be only "localhost" without the instance name of the server. I can even use the name of the computer, the ip-address and 127.0.0.1  I feel a little bit stupid I had tested it with only localhost, but that was maybe when I had the wrong dblib.dll. I want to give a big THANK YOU for your support and your patience with me