Discussion:
Windows Service failed during sys startup...
(too old to reply)
Joao Rego
2006-01-26 17:31:06 UTC
Permalink
Hello,

I use VS.net 2003 and C++
I create a Windows Service derived from ATL::CAtlServiceModuleT.

The service is set to Automatic.
It uses OBDC to connect to a BD in another server and run in SYSTEM account.
Use Win 2000 Server.

When I start it in Service Control Manager it runs OK.

When I reboot the machine I get a system error:
"At least one service or driver failed during system startup..."
In event viewer... I have two errors:
1st. Timeout (30000 millisec) waiting for the Service to connect.
2nd. The Service failed to start due to the following error:
The service did not respond to the start or control request in a
timely fashion.

After the error I go to SCM, start it manualy and it runs OK!!

Thanks for any help on this problem.
Joao Rego
Alexander Nickolov
2006-01-27 01:58:40 UTC
Permalink
I remember in ATL 3 the code setting the service status during
startup was incorrect. Haven't checked it since, maybe it hasn't
been fixed.

Also, make sure you specify proper dependencies for your
service when installing it (e.g. edit the code generated by the
ATL service wizard for service installation). Again, I haven't
checked this since ATL 3, so can't give you particulars.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: ***@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
Post by Joao Rego
Hello,
I use VS.net 2003 and C++
I create a Windows Service derived from ATL::CAtlServiceModuleT.
The service is set to Automatic.
It uses OBDC to connect to a BD in another server and run in SYSTEM account.
Use Win 2000 Server.
When I start it in Service Control Manager it runs OK.
"At least one service or driver failed during system startup..."
1st. Timeout (30000 millisec) waiting for the Service to connect.
The service did not respond to the start or control request in a
timely fashion.
After the error I go to SCM, start it manualy and it runs OK!!
Thanks for any help on this problem.
Joao Rego
Headache
2006-01-27 08:56:03 UTC
Permalink
I take it the 30000 millisecond timeout is the timeout trying to
connect to the database on the other server? What is the DSN to the
database? ODBC to another server somewhere on the network is going to
require dependent services (which I guess must include networking
services) to have started.
Joao Rego
2006-01-27 12:42:02 UTC
Permalink
Hi,

I was doing some tests and I commented the code that uses WMI and ODBC...
well the service starts when computer restarts... it seems that the srvice
starts first than the OBDC or WMI or networking services (as the DB is on
other server) ...

How do I indicate that the service depends on this other services?

Thanks for the help
Joao Rego
Post by Headache
I take it the 30000 millisecond timeout is the timeout trying to
connect to the database on the other server? What is the DSN to the
database? ODBC to another server somewhere on the network is going to
require dependent services (which I guess must include networking
services) to have started.
Headache
2006-01-27 13:12:27 UTC
Permalink
The following method is provider by creating an ATL service (VC6) -
look for _T("RPCSS\0"). This is a COM service and it is dependent on
the RPCSS service. You can see the service name RpcSs at the top of the
general tab if you right click then select properties for "Remote
Procedure Call (RPC)" in the Services. Once you have done this and
registered it as a service again you should be able to right click/
properties / Dependencies tab in the Services.

inline BOOL CServiceModule::Install()
{
if (IsInstalled())
return TRUE;

SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCM == NULL)
{
MessageBox(NULL, _T("Couldn't open service manager"),
m_szServiceName, MB_OK);
return FALSE;
}

// Get the executable file path
TCHAR szFilePath[_MAX_PATH];
::GetModuleFileName(NULL, szFilePath, _MAX_PATH);

// Create the service
SC_HANDLE hService = ::CreateService( hSCM,
m_szServiceName,
m_szServiceName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
szFilePath,
NULL,
NULL,
_T("RPCSS\0"),
NULL,
NULL
);
// Couldn't create service
if (hService == NULL)
{
::CloseServiceHandle(hSCM);
MessageBox(NULL, _T("Couldn't create service"), m_szServiceName,
MB_OK);
return FALSE;
}
Joao Rego
2006-01-27 14:37:03 UTC
Permalink
Hi,

My service inherits from ::CAtlServiceModuleT

It already has that dependency _T("RPCSS\0") in the Install().
In SCM when I right click and select properties and Dependencies it has that
my service depends on Remote Procedure Call(RPC)

How do I say that it depends on ODBC? I don't see a service like ODBC...

Thanks for the tip,
Joao Rego
Post by Headache
The following method is provider by creating an ATL service (VC6) -
look for _T("RPCSS\0"). This is a COM service and it is dependent on
the RPCSS service. You can see the service name RpcSs at the top of the
general tab if you right click then select properties for "Remote
Procedure Call (RPC)" in the Services. Once you have done this and
registered it as a service again you should be able to right click/
properties / Dependencies tab in the Services.
inline BOOL CServiceModule::Install()
{
if (IsInstalled())
return TRUE;
SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCM == NULL)
{
MessageBox(NULL, _T("Couldn't open service manager"),
m_szServiceName, MB_OK);
return FALSE;
}
// Get the executable file path
TCHAR szFilePath[_MAX_PATH];
::GetModuleFileName(NULL, szFilePath, _MAX_PATH);
// Create the service
SC_HANDLE hService = ::CreateService( hSCM,
m_szServiceName,
m_szServiceName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
szFilePath,
NULL,
NULL,
_T("RPCSS\0"),
NULL,
NULL
);
// Couldn't create service
if (hService == NULL)
{
::CloseServiceHandle(hSCM);
MessageBox(NULL, _T("Couldn't create service"), m_szServiceName,
MB_OK);
return FALSE;
}
Headache
2006-01-27 15:21:09 UTC
Permalink
Now I'm confused ...

First of all you determine which services yours is dependent on.
I thought you had done this step. If you haven't then do it.
You can do this by stopping a service and trying to start yours. If
stopping service "A" causes your startup to fail (where it didn't
before) then the likelihood is your service is dependent on service
"A".
Once you have determined which services your service depends on then
you add them to the API call.
If your service does not use COM in any shape or form you can remove
the dependency on RPCSS.
It's boiler-plate code for an ATL COM service. It's now upto you to
edit the boiler-plate code to make it do waht you require.
Joao Rego
2006-01-27 17:13:03 UTC
Permalink
I follow your advice.. and try to found the service..
thanks,
Joao Rego
Post by Headache
Now I'm confused ...
First of all you determine which services yours is dependent on.
I thought you had done this step. If you haven't then do it.
You can do this by stopping a service and trying to start yours. If
stopping service "A" causes your startup to fail (where it didn't
before) then the likelihood is your service is dependent on service
"A".
Once you have determined which services your service depends on then
you add them to the API call.
If your service does not use COM in any shape or form you can remove
the dependency on RPCSS.
It's boiler-plate code for an ATL COM service. It's now upto you to
edit the boiler-plate code to make it do waht you require.
John Sun
2006-01-29 03:09:20 UTC
Permalink
It's pretty obvious that your service cannot start property because it
cannot connect to a remote database at startup based on the following
message:

[1st. Timeout (30000 millisec) waiting for the Service to connect.]

I would suggest the following approaches:

a. Change the default time out value from 30000 milliseconds to longer
value, I know you can do it in connection string.

b. Change the startup code, so your service will be able to start even
without a database connection. And try to reconnect the database after
the service startup.

I don't think the dependency approach will work for you because your
service are not depending on other services on your machine. It's really
not this issue.

HTH

Jianwei
Post by Joao Rego
I follow your advice.. and try to found the service..
thanks,
Joao Rego
Post by Headache
Now I'm confused ...
First of all you determine which services yours is dependent on.
I thought you had done this step. If you haven't then do it.
You can do this by stopping a service and trying to start yours. If
stopping service "A" causes your startup to fail (where it didn't
before) then the likelihood is your service is dependent on service
"A".
Once you have determined which services your service depends on then
you add them to the API call.
If your service does not use COM in any shape or form you can remove
the dependency on RPCSS.
It's boiler-plate code for an ATL COM service. It's now upto you to
edit the boiler-plate code to make it do waht you require.
Continue reading on narkive:
Loading...