Recent

Author Topic: dblib.dll error - MS SQL Express  (Read 6318 times)

ap3000

  • New Member
  • *
  • Posts: 36
dblib.dll error - MS SQL Express
« on: April 26, 2024, 03:28:03 pm »
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][+][-]
  1. program project1;
  2.  
  3. uses
  4.   Classes,
  5.   SysUtils,
  6.   MSSQLConn,
  7.   SQLDB;
  8.  
  9. var
  10.   AConnection: TMSSQLConnection;
  11.   Atransaction: TSQLTransaction;
  12.   AQuery: TSQLQuery;
  13.  
  14. begin
  15.   AConnection := TMSSQLConnection.Create(nil);
  16.   Atransaction := TSQLTransaction.Create(nil);
  17.   AQuery := TSQLQuery.Create(nil);
  18.  
  19.   try
  20.     try
  21.       AConnection.HostName := 'localhost\SQLEXPRESS';
  22.       AConnection.Connected := False;
  23.       AConnection.LoginPrompt := False;
  24.       AConnection.DatabaseName := 'ContactDB';
  25.  
  26.       Atransaction.DataBase := AConnection;
  27.       AConnection.Transaction := Atransaction;
  28.       AQuery.DataBase := AConnection;
  29.  
  30.       AConnection.Open;
  31.  
  32.       AQuery.SQL.Text := 'SELECT * FROM ContactDB';
  33.       AQuery.Open;
  34.  
  35.       while not AQuery.EOF do
  36.       begin
  37.         WriteLn(AQuery.FieldByName('FirstName').AsString, ' ',
  38.           AQuery.FieldByName('LastName').AsString);
  39.       end;
  40.     except
  41.       on E: Exception do
  42.         WriteLn('Error: ' + E.Message);
  43.     end;
  44.   finally
  45.     AConnection.Close();
  46.     AQuery.Free;
  47.     Atransaction.Free;
  48.     AConnection.Free;
  49.   end;
  50.  
  51.   ReadLn;
  52. end.
  53.  
« Last Edit: April 27, 2024, 12:21:21 pm by ap3000 »
Anders Pedersen

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: dblib.dll error - MS SQL Express
« Reply #1 on: April 26, 2024, 03:37:29 pm »
Check dblib.dll requirements. It is possible that it requires some specific Microsoft Visual C++ Redistributable installed (MSVCRT).
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

paweld

  • Hero Member
  • *****
  • Posts: 1561
Re: dblib.dll error - MS SQL Express
« Reply #2 on: April 26, 2024, 04:26:52 pm »
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/topic,66955.msg514263.html#msg514263
Best regards / Pozdrawiam
paweld

NobleStar

  • New member
  • *
  • Posts: 8
Re: dblib.dll error - MS SQL Express
« Reply #3 on: April 26, 2024, 06:58:48 pm »
I believe you also need the Libiconv.dll file to go along with the dblib.dll.

Zvoni

  • Hero Member
  • *****
  • Posts: 3227
Re: dblib.dll error - MS SQL Express
« Reply #4 on: April 26, 2024, 07:06:59 pm »
And his next error will come at line 34…..
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

ap3000

  • New Member
  • *
  • Posts: 36
Re: dblib.dll error - MS SQL Express
« Reply #5 on: April 26, 2024, 08:35:24 pm »
Oeps..  ::)

Quote
And his next error will come at line 34…..

I believe you also need the Libiconv.dll file to go along with the dblib.dll.

And where do I find the Libiconv.dll?
Anders Pedersen

cdbc

  • Hero Member
  • *****
  • Posts: 2562
    • http://www.cdbc.dk
Re: dblib.dll error - MS SQL Express
« Reply #6 on: April 26, 2024, 08:54:09 pm »
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
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

NobleStar

  • New member
  • *
  • Posts: 8
Re: dblib.dll error - MS SQL Express
« Reply #7 on: April 26, 2024, 09:04:02 pm »
You got the DBlib.dll and Libiconv.dll should be in the same zip file.  http://downloads.freepascal.org/fpc/contrib/windows/.

ap3000

  • New Member
  • *
  • Posts: 36
Re: dblib.dll error - MS SQL Express
« Reply #8 on: April 26, 2024, 10:07:25 pm »
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?
Anders Pedersen

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: dblib.dll error - MS SQL Express
« Reply #9 on: April 26, 2024, 10:23:13 pm »
Quote
What can sill be vrong?
Is the IP comm.protocol enabled at the server?
Is it the default instance or it is a named one?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

ap3000

  • New Member
  • *
  • Posts: 36
Re: dblib.dll error - MS SQL Express
« Reply #10 on: April 26, 2024, 10:59:26 pm »
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.
Anders Pedersen

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: dblib.dll error - MS SQL Express
« Reply #11 on: April 27, 2024, 07:02:46 am »
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.
« Last Edit: April 27, 2024, 07:49:07 am by alpine »
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

ap3000

  • New Member
  • *
  • Posts: 36
Re: dblib.dll error - MS SQL Express
« Reply #12 on: April 27, 2024, 12:29:51 pm »
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][+][-]
  1. using System.Data.SqlClient;
  2.  
  3. namespace ConsoleAppMsSqlServer_test;
  4.  
  5. internal class Program
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         string connectionString = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=ContactDB;User ID=ap;Password=Password;";
  10.  
  11.         using (SqlConnection connection = new SqlConnection(connectionString))
  12.         {
  13.             string query = "SELECT * FROM Contacts";
  14.  
  15.             SqlCommand command = new SqlCommand(query, connection);
  16.  
  17.             connection.Open();
  18.  
  19.             SqlDataReader reader = command.ExecuteReader();
  20.  
  21.             Console.WriteLine("Contacts:");
  22.  
  23.             while (reader.Read())
  24.             {
  25.                 string id = reader["Id"].ToString();
  26.                 string firstName = reader["FirstName"].ToString();
  27.                 string lastName = reader["LastName"].ToString();                
  28.  
  29.                 Console.WriteLine($"Id: {id}, First name: {firstName}, Last name: {lastName}");
  30.             }
  31.  
  32.             reader.Close();
  33.         }
  34.     }
  35. }
  36.  
« Last Edit: April 27, 2024, 01:35:13 pm by ap3000 »
Anders Pedersen

dseligo

  • Hero Member
  • *****
  • Posts: 1650
Re: dblib.dll error - MS SQL Express
« Reply #13 on: April 27, 2024, 02:16:34 pm »
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)

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

  • New Member
  • *
  • Posts: 36
Re: dblib.dll error - MS SQL Express
« Reply #14 on: April 27, 2024, 03:15:49 pm »
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?
Anders Pedersen

 

TinyPortal © 2005-2018