I am building a windows service using Delphi 12 (Athens) that listens port 80 and depending on the call it replies back with a message. To do so, I have setup the TService and OnStart it instantiates a TIdHTTPWebBrokerBridge.
In my main program, before the Application.CreateForm statement, I have declared:
if WebRequestHandler <> nil then WebRequestHandler.WebModuleClass := WebModuleClass;
where WebModuleClass: TComponentClass = TMyWebModule; and TMyWebModule = class(TDataModule)
In the DataModule I use a TWebDispatcher and a TFDPhysMySQLDriverLink.
I have created a default action (mtGet) in the WebDispatcher. When I call the service with the default path ("/") I receive the correct responce
Response.Content :=
'<html>' +
'<head><title>My Service</title></head>' +
'<body>My Service Hello</body>' +
'</html>';
So the service and the Http dispatcher work fine. The problem is that in another action (path /check_connection) I want to connect to MySQL v8.0 64bit
if not dbMain.Connected then Begin
try
dbMain.Connected := True;
except
on e: EDatabaseError do
begin
Response.Content := '{"code": 0,"message": "MySQL server connection error:'+E.Message+'"}';
Exit;
end;
end;
End;
where dbMain: TFDConnection;
I am using a TFDPhysMySQLDriverLink in which I have defined in the VendorLib property the path "C:\MySQLConnectors\Win64\libmysql.dll"
The path, as well as, the version of the dll is correct (as I am using exactly the same code in a non-service Server Application which works fine).
But ... I am receiving the following message:
[FireDAC][Phys][MySQL]-314. Cannot load vendor library [C:\MySQLConnectors\Win64\libmysql.dll]. The specified module could not be found Hint: check it is in the PATH or application EXE directories, and has x64 bitness.
Does anybody know why this is happening? Is there any chance that a windows service cannot access local paths?
On another attempt, I copied the dll to the folder that my exe resides and set the VendorLib property at runtime:
ExePath := TPath.GetDirectoryName(GetModuleName(HInstance));
FDPhysMySQLDriverLink.VendorLib := TPath.Combine(ExePath, 'libmysql.dll');
But, again I receive the same message.