Service Application Exception
Posted: Sun 25 Apr 2010 02:14
I have a simple service application that will connect to a database server on start and then launch a thread that sleeps every second. I am setting the TUniConnection Parameters at run time and calling the connect statement. I have narrowed the problem down to the connect statement.
1)With the connect() or connected = true statement commented out, the application runs fine.
2) With the connection enabled in the designer and then I compile (Thus an app that starts with the connection enabled) everything works fine
The only time it fails is when I call connect from code. Any ideas as to why this is happening? Thanks for the help.
I have a sample application but do not see anywhere to attach it.
1)With the connect() or connected = true statement commented out, the application runs fine.
2) With the connection enabled in the designer and then I compile (Thus an app that starts with the connection enabled) everything works fine
The only time it fails is when I call connect from code. Any ideas as to why this is happening? Thanks for the help.
I have a sample application but do not see anywhere to attach it.
Code: Select all
//---------------------------------------------------------------------------
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "DBAccess"
#pragma link "Uni"
#pragma link "dxmdaset"
#pragma resource "*.dfm"
TService1 *Service1;
//---------------------------------------------------------------------------
__fastcall TService1::TService1(TComponent* Owner)
: TService(Owner)
{
}
TServiceController __fastcall TService1::GetServiceController(void)
{
return (TServiceController) ServiceController;
}
void __stdcall ServiceController(unsigned CtrlCode)
{
Service1->Controller(CtrlCode);
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceStart(TService *Sender, bool &Started)
{
/********Database Connection*********/
ses->Username = "wcs";
ses->Password = "password";
ses->Server = "10.20.1.7\SQLEXPRESS";
ses->LoginPrompt = false;
ses->ConnectDialog = NULL;
ses->Connected = true; //Causes Service to Crash
//ses->Connect(); //Causes Service to Crash
/************************************/
myThread = new TestThread(false);
Started = true;
}
//---------------------------------------------------------------------------
void __fastcall TService1::ServiceStop(TService *Sender, bool &Stopped)
{
if(myThread) {
myThread->Terminate();
myThread->WaitFor();
delete myThread;
myThread = NULL;
}
Stopped = true;
}
//---------------------------------------------------------------------------
Code: Select all
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "TestThread.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(&UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall TestThread::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall TestThread::TestThread(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TestThread::Execute()
{
while(!Terminated) {
::Sleep(1000);
}
}
//---------------------------------------------------------------------------