Windows Services + Oracle Connection  
Author Message
SOTY_Programmer





PostPosted: Visual C# General, Windows Services + Oracle Connection Top

I'll get right to the point, I'm creating a Windows Service (C#), and so far things are working up to the point where I want to connect to Oracle 9i (9.2.1 to be specific).

I first tested my connection string out in a Windows Application first, and that worked. So then my next step was just to copy and paste that code into the Windows Service OnStart() sub. But when I build and install the service, it says that it can't start because it has no tasks to do. Well that's just not true, i want it to talk to the oracle database and add a certain value into it.

Any ideas on how abouts I can resolve this

If you wish to see some code, request it and I'll make sure you get some. But I'm sure it if worked in my Windows app, it should work in the Windows service...shoudln't it



Visual C#17  
 
 
SOTY_Programmer





PostPosted: Visual C# General, Windows Services + Oracle Connection Top

Is this something no one has ever seen or am I doing the impossible. Any advice would be nice at this point and time. Thanks! :)


 
 
Udhaya Kumar D





PostPosted: Visual C# General, Windows Services + Oracle Connection Top

Copy the database connection and other stuff to a seperate function and run it as a seperate thread.

Start the thread from the OnStart() Event

Sample Code:
=========================================================

private System.Threading.Thread workerThread = null;

protected override void OnStart(string[] args)
{
if ((workerThread == null) || ((workerThread.ThreadState & (System.Threading.ThreadState.Unstarted | System.Threading.ThreadState.Stopped)) != 0))
{
workerThread = new Thread(new ThreadStart("name of the function"));
workerThread.Start();
}
}

protected override void OnStop()
{
if ((workerThread != null) && (workerThread.IsAlive))
{
Thread.Sleep(3000);
workerThread.Abort();
}

}

 
 
SOTY_Programmer





PostPosted: Visual C# General, Windows Services + Oracle Connection Top

Perfect, I haven't tried it yet, but it looks like this could work! Thanks my friend

SOTY_Programmer