wxSQLite3 brokes Windows service Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
Livy
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jul 05, 2011 2:26 pm

wxSQLite3 brokes Windows service

Post by Livy »

I'm trying to run my program as a Windows service. The complete Windows service example can be found here. It is easy to understand and compiled, but when I replace my code in the sample with mine it does not work anymore. After 2 hours analizing, I finally found wxSQLite3 is the cause of the problem. Adding only one line of wxSQLite3 code, and the service cannot start at all. For example:

Code: Select all

VOID SvcInit( DWORD dwArgc, LPTSTR *lpszArgv)
{
	// TO_DO: Declare and set any required variables.
	//   Be sure to periodically call rlReportSvcStatus() with 
	//   SERVICE_START_PENDING. If initialization fails, call
	//   rlReportSvcStatus with SERVICE_STOPPED.

	// Create an event. The control handler function, rlSvcCtrlHandler,
	// signals this event when it receives the stop control code.
	ghSvcStopEvent = CreateEvent(
		NULL,    // default security attributes
		TRUE,    // manual reset event
		FALSE,   // not signaled
		NULL);   // no name

	if ( ghSvcStopEvent == NULL)
	{
		rlReportSvcStatus( SERVICE_STOPPED, NO_ERROR, 0 );
		return true;
	}

	// Report running status when initialization is complete.
	rlReportSvcStatus( SERVICE_RUNNING, NO_ERROR, 0 );

	// TO_DO: Perform work until service stops.
	wxSQLite3Database db;

	while(1)
	{
		// Check whether to stop the service.
		WaitForSingleObject(ghSvcStopEvent, INFINITE);
		// This function waits until the event object is in the signaled state or the time-out interval elapses.

		rlReportSvcStatus( SERVICE_STOPPED, NO_ERROR, 0 );
		return true;
	}
}
When starting the service, I receive this error: "Windows could not start the [service name] service on Local Computer. Error 1053: the service did not respond to the start or control request in a timely fashion." The service start normally without the line "wxSQLite3Database db;". I've replace this line with "wxSQLite3Database::InitializeSQLite();" but still no luck. I even think of elevator because using database means writing to disk, and try using wxOutputStream to write a string to a file in C:\Program Files\ and the service still runs and writes successfully (its privilege is pretty high). I also tried open wxSocketServer, parse some JSON files with wxJSON and the service still starts and works. What could be wxSQLite3 doing with the service here?

I'm using wxSQLite3 v2.1.1, VC9 on Windows 7.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxSQLite3 brokes Windows service

Post by utelle »

Livy wrote:I'm trying to run my program as a Windows service. The complete Windows service example can be found here. It is easy to understand and compiled, but when I replace my code in the sample with mine it does not work anymore. After 2 hours analizing, I finally found wxSQLite3 is the cause of the problem. Adding only one line of wxSQLite3 code, and the service cannot start at all. For example:

Code: Select all

VOID SvcInit( DWORD dwArgc, LPTSTR *lpszArgv)
{
	// TO_DO: Declare and set any required variables.
	//   Be sure to periodically call rlReportSvcStatus() with 
	//   SERVICE_START_PENDING. If initialization fails, call
	//   rlReportSvcStatus with SERVICE_STOPPED.

	// Create an event. The control handler function, rlSvcCtrlHandler,
	// signals this event when it receives the stop control code.
	ghSvcStopEvent = CreateEvent(
		NULL,    // default security attributes
		TRUE,    // manual reset event
		FALSE,   // not signaled
		NULL);   // no name

	if ( ghSvcStopEvent == NULL)
	{
		rlReportSvcStatus( SERVICE_STOPPED, NO_ERROR, 0 );
		return true;
	}

	// Report running status when initialization is complete.
	rlReportSvcStatus( SERVICE_RUNNING, NO_ERROR, 0 );

	// TO_DO: Perform work until service stops.
	wxSQLite3Database db;

	while(1)
	{
		// Check whether to stop the service.
		WaitForSingleObject(ghSvcStopEvent, INFINITE);
		// This function waits until the event object is in the signaled state or the time-out interval elapses.

		rlReportSvcStatus( SERVICE_STOPPED, NO_ERROR, 0 );
		return true;
	}
}
When starting the service, I receive this error: "Windows could not start the [service name] service on Local Computer. Error 1053: the service did not respond to the start or control request in a timely fashion." The service start normally without the line "wxSQLite3Database db;". I've replace this line with "wxSQLite3Database::InitializeSQLite();" but still no luck. I even think of elevator because using database means writing to disk, and try using wxOutputStream to write a string to a file in C:\Program Files\ and the service still runs and writes successfully (its privilege is pretty high). I also tried open wxSocketServer, parse some JSON files with wxJSON and the service still starts and works. What could be wxSQLite3 doing with the service here?

I'm using wxSQLite3 v2.1.1, VC9 on Windows 7.
You didn't tell how you built your service application and especially wxSQLite3. Do you link wxWidgets and wxSQLite3 statically to your application? Or do you use DLLs?

My guess is that your service application fails to load the SQLite DLL. Make sure that the SQLite DLL can be found or alternatively consider to link SQLite statically into wxSQLite3. (There are several posts on this forum explaining how to compile SQLite3 yourself.)

Regards,

Ulrich
Livy
In need of some credit
In need of some credit
Posts: 5
Joined: Tue Jul 05, 2011 2:26 pm

Re: wxSQLite3 brokes Windows service

Post by Livy »

My bad. You're right. I forgot to place the DLL file to the exe file folder. I thought of many reason but did not think of that :( . I should be more careful next time.
Post Reply