Re: NT Service Problem
void MyService::ServerUpdates()
{
CDatabase db;
CString strVal;
CRecordset rs(&db);
CString sqlCommand;
TRY
{
//Connect to the Database
OpenDbConnection(&db);
if(db.IsOpen())
{
sqlCommand = "My SQL Query";
rs.Open(AFX_DB_USE_DEFAULT_TYPE,sqlCommand);
DWORD dRowsFetched = rs.GetRowsFetched();
rs.Close();
db.Close();
if(dRowsFetched > 0)
{
if(nUpdateThrdCount <= 0) //Global Variable which is greater than
zero if thread below is already started
{
handleUT = (HANDLE) _beginthread(SvrUpdateThreadProc,0,NULL); // create
thread
//handleUT global again
}
else
return;
}
else
return;
}
}
CATCH(CDBException, eDB)
{
//Write the Error to Log File
}
END_CATCH
}
This is the function I am calling in the service every 15 mins to check for
a condition
If the condition is satisfied a new thread is started.
I am also calling this function in ServiceMain
The Service starts & stops successfully if I dont call this function.
If this function is called then there is a problem in stop of service.
The service is eventually stopped , but it does not return Success.
{There are other functions also that I am calling from service main & they
also deal with threads, but I dont have any problems with those.
Its just this function that is causing problems}
Has this something to do with the time out value.
How can I extend the timeout period for stopping the service.If yes, how?
Thanks again for your help!
"Joseph M. Newcomer" wrote:
There is an error in your shutdown code that is causing an exception. This exception
causes the service to terminate, but it represents a bug. You will have to attach your
debugger to the service and then initiate a shutdown to see where it is failing.
What you do, in terms of db connection and threads, isn't terribly informative; all you've
really said is "my program fails, what did I do wrong?". The answer is "Yes, you did
something wrong. The solution is to find it and fix it". Without more information, such
as knowing where the fault occurs, there is no hope of saying anything more. That's what
debuggers are all about.
So the way you make the service stop successfully is to find and fix the bug.
joe
On Sun, 10 Sep 2006 07:13:02 -0700, Susanna <Susanna@discussions.microsoft.com> wrote:
Hi, :)
I have an NT Service written in MFC.
There are no problems starting the service, but when I try to stop or pause
the service, I get this error 1064 i.e
"An exception occurred in the service when handling the control request"
The service is stopped but it does not return a success.
I am doing somethings (like connecting to db, starting some new threads
etc), when the service starts or is running.I believe the problem is here.
How can I make the service stop successfully??
Please reply asap.Thanks.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm