NT Service not working with ADO???

NT Service not working with ADO???

Post by Todd Super » Tue, 12 Oct 2004 22:41:14


Hey guys,

I don't remember if I've posted this problem here before, but I have
Delphi 7, and I'm writing a Windows NT Service. I seem to have a problem
accessing database functions, either writing or reading.

I am accessing an ADO database (MS SQL) using the ADO components (Query, and
Command).


This is my Execute procedure....

Procedure ExecuteService;
Var
ErrMsg : String;
Begin
Try
Begin
MainProcess;
End;
Except
On E: Exception Do
Begin
RM_FUNC.WriteTxtLog(2,'[ERROR] - Encountered a problem in
SERVICE EXECUTE!');
ErrMsg := SysErrorMessage(GetLastError);
WriteTxtLog(1,ErrMsg);
End;
End;
End;


Where you see in the procedure "MainProcess", I have a single line... I have
commented everything out so that I can narrow it down. It errors out on the
VERY first line within the MAINPROCESS procedure.

This line that it errors out on is: RM_FUNC.ReadLab(RM_GLOBAL.CurrLab);

This line merely sends to the ReadLab procedure the current lab #. What I do
then is pull a single field out. This procedure ReadLab looks like this:



Procedure ReadLab(LabNum : Integer);
Var
SQLStatement : String;
Begin
SQLStatement := ('SELECT T1.REPORT_FOLDER_PATH '
+ 'FROM LAB T1 '
+ 'WHERE (T1.ID = ' + IntToStr(LabNum) + ')');

RM_DATA.RM_DM.RM_Input.Active := False;
RM_DATA.RM_DM.RM_Input.SQL.Clear;
RM_DATA.RM_DM.RM_Input.SQL.Text := SQLStatement;
RM_DATA.RM_DM.RM_Input.Active := True;

Begin
RM_GLOBAL.LabRootPath :=
RM_DATA.RM_DM.RM_Input.FieldByName('REPORT_FOLDER_PATH').AsString;
End;

RM_DATA.RM_DM.RM_Input.Active := False;
RM_DATA.RM_DM.RM_Input.SQL.Clear;
End;


With text logging that I've been putting in, I can pinpoint the error as
occuring RIGHT at the line that says: RM_DATA.RM_DM.RM_Input.Active :=
False;


Any idea what I'm doing wrong? Am I not initializing something???

Oh yeah, if you need to see it, the procedure that calls ExecuteService is:
"ServiceExecute" and it looks like this:

(* MAIN SERVICE EXECUTE Procedure *)
Procedure TIntService.ServiceExecute(Sender: TService);
Begin
While NOT Terminated Do
Begin
ExecuteService;
Sleep(10000);
ServiceThread.ProcessRequests(False);
End;
End;


Thanks, any help you guys can give me I would REALLY REALLY appreciate. I've
written a few services before, but none that access databases. I have one
that automatically prints files that appear in a folder, one that does a
text file to text file conversion (parses a file and exports it into a
different format). But this is the frist database program that I have tried
to convert into a Service.

Also, I have a regular application where I use all these same functions (I
tried to create it as an application first before I tried to convert it to a
service) and it all works PERFECTLY. Just not when I try to convert it as a
service.


THANKS!!!!!!!!!

Todd
 
 
 

NT Service not working with ADO???

Post by danny heij » Wed, 13 Oct 2004 03:09:01

> I am accessing an ADO database (MS SQL) using the ADO components (Query, and

Every thread that uses ADO has to call CoInitialize on entry and
CoUnitialize on exit.

Danny
---

 
 
 

NT Service not working with ADO???

Post by Todd Super » Wed, 13 Oct 2004 03:29:28

Hi, Thanks Danny!!

Can you tell me exactly what you mean by a thread? How do I know if I'm
going into a seperate thread?
Would I do it just before calling the ReadLab procedure (is that a seperate
thread??)

Or would I call CoInitialize right when I execute the ServiceExecute and
then call CoUninitialize right after?

And do I just enter CoInitialize or is it something like ADO.CoInitialize?


Thanks!

Todd



and
 
 
 

NT Service not working with ADO???

Post by Todd Super » Wed, 13 Oct 2004 21:52:11

Hey Brian, it doesn't seem to make a difference....

(* MAIN SERVICE EXECUTE Procedure *)
Procedure TIntService.ServiceExecute(Sender: TService);
Begin
// CoInitializeEx(nil, 0);
While NOT Terminated Do
Begin
CoInitialize(nil);
ExecuteService;
CoUninitialize;
Sleep(10000);
ServiceThread.ProcessRequests(False);
End;
End;


It still errors out in the same place. What could I be doing wrong? It
didn't work at first, so I had to add the ActiveX in the USES clause.

Should I be doing this JUST before I access the ADO database components or
someting?

I don't know why this is so hard for me to understand. I would love to see
an example Service that accesses an MS SQL database using ADO, but I can't
seem to find one anywhere....

Thanks,

Todd




seperate
ADO.CoInitialize?
 
 
 

NT Service not working with ADO???

Post by Heikki Wr » Fri, 15 Oct 2004 15:32:41

Hey !
Could somebody explain what are these mysterious
coinitialize/counitialize, because they are not documented in Delphi
help files ?
Anyway, I have a Delphi7 NTService application that is working
(perfectly ?) now,
when I added coinitialize just after entering the (sub)thread and
couninitialize just before
suspending it. This app uses ADO to access MSSQL/Oracle db.
Coinitialize is also
in the app main thread, just before opening the ADO connection.
This cleared the mysterious ADO error (that I reported here on Friday
8th) when running W2K !
 
 
 

NT Service not working with ADO???

Post by Dennis » Sat, 16 Oct 2004 01:17:49

>Could somebody explain what are these mysterious coinitialize /

Not so mysterious since they are documented in the default Win32.hlp files
since they are standard Win32 API functions.


Dennis Passmore
Ultimate Software, Inc.
 
 
 

NT Service not working with ADO???

Post by Todd Super » Wed, 20 Oct 2004 05:31:37

Hey Heikki,

Can you e-mail me?

XXXX@XXXXX.COM

I want to ask you a question, I just can't seem to get this working.

No matter where I put the co-initialize it just isn't working. I'm
desperate...

Thanks,

Todd