Cannot connect to MSSQL 2000 lazarus / 16-Databases ---------------------------------------------------------------------- rgh · 2014-04-05 11:40 This is my first attempt to make a trivial Lazarus application. Just trying to connect to a remote MSSQL 2000 server that hosts a copy of the Northwind example database. I have a form with a TSQLConnector component on it and procedure TForm1.Button1Click(Sender: TObject); begin   SQLConnector1.Connected:=true; end;    The properties of the TSQLConnector are set: object SQLConnector1: TSQLConnector     Connected = False     LoginPrompt = False     DatabaseName = 'Northwind'     KeepConnection = False     Password = 'test_password'     Transaction = SQLTransaction1     UserName = 'test_user'     HostName = 'myserver.xxxxxx.com:1234'     LogEvents = []     ConnectorType = 'MSSQLServer'     left = 48     top = 40   end    As you see, the server is not running on the default MSSQL port. I've put a copy of two dll files in the same directory as the Lazarus generated exe, that is dblib.dll libiconv2.dll However, when I run the exe (ie not from within the IDE) & click the button, I get the error: TMSSQLConnection : Error 20002 : Adaptive Server connection failed Could anyone tell me what I'm doing wrong here? Windows xp sp3 Lazarus 1.2.0 dblib_0.91 Richard ---------------------------------------------------------------------- marcov · 2014-04-05 11:48 Which freetds dll do you use? ---------------------------------------------------------------------- BigChimp · 2014-04-05 11:54 @Marco: dblib_0.91 which should be ok. @rgh: have you tried connecting using other tools (e.g. telnet) to rule out firewall/network issues? Also, do dll and exe bitness match - are you using the 32 bit dll with 32 bit compiled exe (or 64 bit dll with 64 bit compiled exe) ---------------------------------------------------------------------- rgh · 2014-04-05 14:35 Quote from: BigChimp on April 05, 2014, 01:54:32 pm@Marco: dblib_0.91 which should be ok. So those two dll files should be sufficient? Are they the freetds files that marcov mentions? Quote@rgh: have you tried connecting using other tools (e.g. telnet) to rule out firewall/network issues? It's not a network or firewall problem. I can connect using both MS SQL Query Analyzer & the Delphi app I'm wondering if I can port to Lazarus. QuoteAlso, do dll and exe bitness match - are you using the 32 bit dll with 32 bit compiled exe (or 64 bit dll with 64 bit compiled exe) It's the dblib_0.91 win32 files I've used. Lazarus project options>Compiler options>Config & Target>Target-specific options Win32 gui is ticked. ---------------------------------------------------------------------- BigChimp · 2014-04-06 07:58 Quote from: rgh on April 05, 2014, 04:35:00 pmSo those two dll files should be sufficient? Are they the freetds files that marcov mentions? Now I'm wondering what gave you the idea to download them? See http://wiki.lazarus.freepascal.org/mssqlconn#Installation You may need additional Visual C++ runtime files, don't know; please check the readme for the download. Quote from: rgh on April 05, 2014, 04:35:00 pmIt's not a network or firewall problem. I can connect using both MS SQL Query Analyzer & the Delphi app I'm wondering if I can port to Lazarus. TBH, network/addressing issues seem to be the only thing left (e.g. is the hostname:port notation correct in your code). If I was you I'd sniff the traffic with Wireshark and see where things go wrong. Quote from: rgh on April 05, 2014, 04:35:00 pmQuoteAlso, do dll and exe bitness match - are you using the 32 bit dll with 32 bit compiled exe (or 64 bit dll with 64 bit compiled exe) It's the dblib_0.91 win32 files I've used. That's good - assuming you have Windows XP 32 bit, which is quite likely... Quote from: rgh on April 05, 2014, 04:35:00 pmLazarus project options>Compiler options>Config & Target>Target-specific options Win32 gui is ticked. That has nothing to do with compiler bitness... (though it may seem like it). It determines whether an application is a console or GUI application (on Windows only). Hope you'll get it figured out... ---------------------------------------------------------------------- BigChimp · 2014-04-06 11:12 Just tested on Win XP SP3 x86 with * dblib 0.9.1 downloaded via link on mssqlconn wiki page * dblib.dll md5 1819aec485bedd8f7b8dd75283e9b393, size 229,376 * libiconv2.dll, md5 fd1dc6c680299a2ed1eedcc3eabda601, size 978,432 * had to install Microsoft Visual C++ 2005 redistributable package * my pasql tool (using mssqlconn): https://bitbucket.org/reiniero/smalltools/downloads/pasql.exe For a host 192.168.1.10 listening on port 1433, username sa, password password (ip address/details changed to protect the guilty): Code: [Select]pasql -h 192.168.1.10:1433 --type=SQLSERVER --username=sa --password="password" connects fine to a remote SQL Server 2000 database... ---------------------------------------------------------------------- rgh · 2014-04-06 15:35 Thanks for your help BigChimp & marcov, I've found out what the problem is. At the server 'Force protocol encryption' is switched on, using the SQL Server Network Utility. Switching it off, both my Lazarus app & BigChimp's pasql work fine. Because this traffic is traveling over the Internet, switching it off isn't really an option. Experimenting, my Lazarus app will work, with encryption on, if I use a TODBCConnection instead of a TSQLConnector. ---------------------------------------------------------------------- BigChimp · 2014-04-06 15:39 Hmmm... Freetds does have support for encrypted connections http://www.freetds.org/faq.html#encrypted You'll probably need to read the freetds docs & set up freetds.conf for that. Haven't looked into it. Anyway, glad you figured it out... PS: unsupported, outdated, MS SQL Server 2K directly connected to the internet... ehmmm... interesting security evaluation there... *cough* ---------------------------------------------------------------------- LacaK · 2014-04-09 11:40 Quote from: BigChimp on April 06, 2014, 05:39:21 pmHmmm... Freetds does have support for encrypted connections http://www.freetds.org/faq.html#encrypted You'll probably need to read the freetds docs & set up freetds.conf for that. Haven't looked into it. http://www.freetds.org/userguide/freetdsconf.htm encryption=request ---------------------------------------------------------------------- rgh · 2014-04-14 10:44 Quote from: LacaK on April 09, 2014, 01:40:27 pm http://www.freetds.org/userguide/freetdsconf.htm encryption=request Is it possible to set that parameter via the TSQLConnector component somehow? ---------------------------------------------------------------------- LacaK · 2014-04-14 12:41 AFAIK no. It is because FreeTDS DB-Lib which is used by TMSSQLConnection does not support this. First must be added support for FreeTDS, then we can follow.