NT Service with ADO

NT Service with ADO

Post by almc » Sun, 11 Jun 2006 00:23:15



Hi there!

I'm developing a windows service (or should I say trying...), that needs
to access data in some database.
I have already a library (in a separate dll, with static linking) that
uses ADO via the COM Interface (no #import stuff), to access data.
Also, Ie started by looking at some samples at www.codeproject.com,
specially the article by PJ Naughter and he library CNTService framework.
Now the problem: the service is installed correctly, but it will always
fail to start, and it reports the error: 1053 - "The service did not
respond to the start or control request in a timely fashion."

Can anyone tell me what the problem might be?
Tanks in advance for your time.
Antnio Carvalho
 
 
 

NT Service with ADO

Post by Kurt » Sun, 11 Jun 2006 00:48:16

Without seeing any code it's hard to say, are you trying to open a
connection in your startup routine? Did you call CoInitialize?

 
 
 

NT Service with ADO

Post by almc » Sun, 11 Jun 2006 02:18:31

Na , Kurt < XXXX@XXXXX.COM > escreveu:


Yes, I'm calling the CoInitialize for each thread that I start.
This is my startup routine..

----- begin
void ServiceMain(DWORD /*dwArgc*/, LPTSTR* /*lpszArgv*/)
{
WSAStartup(MAKEWORD(1,1), &m_wsData); // Fill in WSA info
if (m_wsData.wVersion==0)
{
ReportStatusToSCM(SERVICE_STOPPED, ::GetLastError(), 0, 1, 0);
return;
}

//register our control handler
RegisterCtrlHandler();

//Pretend that starting up takes some time
ReportStatusToSCM(SERVICE_START_PENDING, NO_ERROR, 0, 1, 0);
ReportStatusToSCM(SERVICE_RUNNING, NO_ERROR, 0, 1, 0);

//Report to the event log that the service has started successfully
m_EventLogSource.Report(EVENTLOG_INFORMATION_TYPE,
CNTS_MSG_SERVICE_STARTED, m_sDisplayName);

AfxBeginThread(ThreadWork, this, THREAD_PRIORITY_BELOW_NORMAL);

//The tight loop which constitutes the service
while (!GetWantStop())
{
//As a demo, we just do a message beep
CSocketListener lstnr;
lstnr.Listen(this);
Sleep(500);
}

//Pretend that closing down takes some time
ReportStatusToSCM(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 0);
Sleep(1000);
ReportStatusToSCM(SERVICE_STOPPED, NO_ERROR, 0, 1, 0);

//Report to the event log that the service has stopped successfully
m_EventLogSource.Report(EVENTLOG_INFORMATION_TYPE,
CNTS_MSG_SERVICE_STOPPED, m_sDisplayName);
}
---- end

The thread pointed by ThreadWork, is the one that actualy uses the ADO
Connection; as you can also see, there is a cycle with a socket listener,
for some user interface for special tasks.

I hope it is enough...
 
 
 

NT Service with ADO

Post by Kurt » Sun, 11 Jun 2006 02:25:30

I don't know the socket class you are using but doesn't the listen function
block your main thread?
 
 
 

NT Service with ADO

Post by almc » Tue, 13 Jun 2006 17:46:57


I've also tried without the cycle with the listener, and even without the
other worker thread and the listener cycle...

--
Utilizar M2, Cliente de e-mail revolucionio do Opera:
http://www.yqcomputer.com/