ODBC Connection in a Windows service lazarus / 16-Databases ---------------------------------------------------------------------- relocate · 2021-09-21 06:44 I want to connect to an MSSQL Server via a service in Windows. But it won't connect. In a standard program everything works as it should, but not in the service. The suggested solution to create a system DNS doesn't help. The handles are created, only when it comes to the Connection it goes wrong. I dont't use Lazarus only pure Free Pascal and the odbcsqldyn unit. ---------------------------------------------------------------------- ccrause · 2021-09-21 08:24 Just thinking out loud - could this be a privilege issue because the service doesn't run within a user context? Can you retrieve an error code, this could help in identifying the problem. ---------------------------------------------------------------------- Zvoni · 2021-09-21 08:27 1) is your service dependent on the Database-Service? As in: Is the DB-Service up and running, before your Service starts? 2) Have you tried within your service to Login with your Windows-user- Account? https://www.codeproject.com/Questions/185651/ODBC-through-Windows- Service-Win-7-x64 ---------------------------------------------------------------------- relocate · 2021-09-21 09:27 @ccrause I only get -1 as errorcode. That's the returncode from SQLConnect, I don't know if i can get any other code. @zvoni 1) No, the Database is located on an server which is allready running, so no dependences. 2) Yes, I allready tried it. But you brought me onto the right course, I took the wrong user. (local instead of domain user), it works, thank you! ---------------------------------------------------------------------- Zvoni · 2021-09-21 10:11 Ah, yes. Domain-User makes more sense, if the DB-Server is on another machine of the Network ---------------------------------------------------------------------- relocate · 2021-09-21 10:28 Yes, I thought I'd took the right user, but NO. ---------------------------------------------------------------------- paweld · 2021-09-21 10:52 try initialize multithreading for the COM objects: 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 uses  ComObj; begin  CoInitializeEx(nil, COINIT_MULTITHREADED);  SQLConnection1.Connect;  //queries  SQLConnection1.Disconnect;  CoUnInitialize; end; ---------------------------------------------------------------------- Zvoni · 2021-09-21 12:40 Pawel what's that got to do with the initial problem? The OP has a Network-Service which wasn't running under a User-Context trying to access a network-ressource which is bound to fail ---------------------------------------------------------------------- relocate · 2021-09-21 13:10 @paweld according to zvoni I would ask the same, on which circumstances I should use this for the problem. Or did the answer just go to the wrong question? ---------------------------------------------------------------------- paweld · 2021-09-21 15:16 Admittedly I am not using ODBC but SDAC components, but with windows service the component does not want to connect to MSSQL until multithreading is initiated for COM objects. ---------------------------------------------------------------------- relocate · 2021-09-22 07:04 Thanks for the clarification, I don't know if there is a correlation, but with the solution through the windows service it works. And it seems to be a valued solution because in some cases services need user rights to forefill their tasks.