Page 1 of 1

Connect to SQL Server from Service Application

Posted: Tue 25 Sep 2007 11:36
by Belitski
Hello,
We are using trial version of components for Delphi 5.
Two computer configuration in the domain: Developer computer and computer with SQL Server.
We have Service application on the developer computer.
In design mode we can connect to the SQL Server by setting in object inspector Connected := True on TMSConnection component. This works fine.
Trouble begin at attempting to start Service Application. The following code hang:
repeat
try
dbMain.Connected := true;
if dbMain.Connected then
Break;
except
on E: Exception do
begin
AddToLog('Connect failed with message: ' + E.Message);
end;
end;

sleep(5000); // 5 sec
inc(vCount);
Application.ProcessMessages;
until (vCount > (12 * 15)); // 15 min

The message that comes says: "Operation aborted".
Any ideas what is wrong?
Thank you very much.
Vladimir

Posted: Tue 25 Sep 2007 12:13
by Antaeus
Most likely the reason of this problem is the nag screen trying to popup in your service. This problem should disappear in a registered edition of SDAC. Registered users do not report us about such problems.

Posted: Tue 25 Sep 2007 12:31
by Belitski
As far as I understand, the nag screen comes when Delphi is not started. But it came only by the first attempt to start Service, afterwards I didn't see it. I thought, the component has "remembered" the first start somewhere in the registry.
However, the Service never started (never came through the first connect). Besides of that, the checkbox for the Service allowing Data exchange with desktop is checked. Why should it be the problem?

Posted: Tue 25 Sep 2007 15:47
by yeohray
I am a registered SDAC user, and use SDAC in a heavily threaded Windows service application. I have never encountered any issues with SDAC when used in my service application. The problem is probably what Antaeus has stated - the nag screen has popped up, and probably does not have a parent form in which it can be displayed correctly.

I would suggest logging to a log file, in the OnServiceStart event, to check if the execution even reaches that far.

Posted: Wed 26 Sep 2007 07:09
by Belitski
Thank you for answer.
Yes, it comes so far. The code in my first post is inside the
function ConnectToDatabseWhenServiceStart that is called from
the handler OnServiceStart:

procedure TMC.ServiceStart(Sender: TService; var Started: Boolean);
begin
sDatabase := System.ParamStr(1);
sTablePrefix := System.ParamStr(2);
sUsername := System.ParamStr(3);
sPassword := Decrypt(HexStrToStr(System.ParamStr(4)), cCryptKey);

LogLevel := StrToIntDef(System.ParamStr(5), 0);

sPathLogFile := System.ParamStr(6);

dmMain := TdmMain.CreateDM(Application, bVisible, sPathLogFile);

if dmMain.ConnectToDatabseWhenServiceStart then
begin
...........
Started := True;
end
else
Started := False;
end;

Posted: Wed 26 Sep 2007 09:13
by yeohray
Guess it's the nag screen then. If you want to, you can send me your code (assuming it's just a small test app), and I can compile it for you using the registered version of SDAC 4.1, so that you can determine if its really an issue with the nag screen, assuming it's ok with the CoreLab people. BTW, I use Delphi 7.

Posted: Wed 26 Sep 2007 10:28
by Belitski
Thank you very much for suggestion. The project is too big to test it this way. I hope you are right and I'll wait before we get the licence.