Using ADO.NET in windows service. I'm getting no events (e.g. RecordChangeComplete)

M

ML

Hello,

I have some small code that opens a connection to an oledb-provider and
opens a recordset. Then creates a delegate to a RecordChangeComplete event
on the recordset.
When I put this code in a service (have tried both OnStart and in a separate
thread) I never get any RecordChangeComplete events. Although using the
exact same code in a form application the event works fine.
In both cases I can see that the oledb-provider is sending the right events,
but it seems they are trapped by the service somehow.

I have used the provider in services (written in C++) before, but never
using ADO / ADO.NET and it has always worked fine.

So what is ADO doing that behaves differently in a service-application than
in a Forms-application?

The code in the service looks like this:

protected override void OnStart(string[] args)
{
m_cn = new Connection();
m_rs = new Recordset();
m_cn.Open(Providerstring, "", "", 0);
m_rs.Open(Tablestring, m_cn, CursorTypeEnum.adOpenDynamic,
LockTypeEnum.adLockReadOnly, 0);
ADODB.RecordsetEvents_RecordChangeCompleteEventHandler delRecordComplete
= new
RecordsetEvents_RecordChangeCompleteEventHandler(RecordChangeComplete);
m_rs.RecordChangeComplete += delRecordComplete;
}

/Morgan L
 
S

Sahil Malik

Try this trick

http://dotnetjunkies.com/WebLog/sahilmalik/archive/2004/12/06/35295.aspx

To help you diagnose/debug your windows service like a windows app. Check
and see if the delegate is null for any crazy reason.

Also, by doing the above, and running it in debugmode, you are essentially
then running a windows application/not a service - that way we'd find out if
"Service" has something to do with it, or indeed there is something funny
with the code.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
M

ML

I tried the trick and while running it as a normal windows application it
worked fine, all events came as they should.
When running it as a service I still don't get any events.
I tried both with .NET 1.1 and .NET 2.0 (2005 beta 1), and they produced the
same result.

Can there be a problem with message looping etc?

/Morgan L



Sahil Malik said:
Try this trick

http://dotnetjunkies.com/WebLog/sahilmalik/archive/2004/12/06/35295.aspx

To help you diagnose/debug your windows service like a windows app. Check
and see if the delegate is null for any crazy reason.

Also, by doing the above, and running it in debugmode, you are essentially
then running a windows application/not a service - that way we'd find out
if "Service" has something to do with it, or indeed there is something
funny with the code.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


ML said:
Hello,

I have some small code that opens a connection to an oledb-provider and
opens a recordset. Then creates a delegate to a RecordChangeComplete
event on the recordset.
When I put this code in a service (have tried both OnStart and in a
separate thread) I never get any RecordChangeComplete events. Although
using the exact same code in a form application the event works fine.
In both cases I can see that the oledb-provider is sending the right
events, but it seems they are trapped by the service somehow.

I have used the provider in services (written in C++) before, but never
using ADO / ADO.NET and it has always worked fine.

So what is ADO doing that behaves differently in a service-application
than in a Forms-application?

The code in the service looks like this:

protected override void OnStart(string[] args)
{
m_cn = new Connection();
m_rs = new Recordset();
m_cn.Open(Providerstring, "", "", 0);
m_rs.Open(Tablestring, m_cn, CursorTypeEnum.adOpenDynamic,
LockTypeEnum.adLockReadOnly, 0);
ADODB.RecordsetEvents_RecordChangeCompleteEventHandler
delRecordComplete = new
RecordsetEvents_RecordChangeCompleteEventHandler(RecordChangeComplete);
m_rs.RecordChangeComplete += delRecordComplete;
}

/Morgan L
 
S

Sahil Malik

I've written windows services with events before and didn't find any strange
peculiarities as far as events go .. I'm perplexed on this one !!!

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


ML said:
I tried the trick and while running it as a normal windows application it
worked fine, all events came as they should.
When running it as a service I still don't get any events.
I tried both with .NET 1.1 and .NET 2.0 (2005 beta 1), and they produced
the same result.

Can there be a problem with message looping etc?

/Morgan L



Sahil Malik said:
Try this trick

http://dotnetjunkies.com/WebLog/sahilmalik/archive/2004/12/06/35295.aspx

To help you diagnose/debug your windows service like a windows app. Check
and see if the delegate is null for any crazy reason.

Also, by doing the above, and running it in debugmode, you are
essentially then running a windows application/not a service - that way
we'd find out if "Service" has something to do with it, or indeed there
is something funny with the code.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


ML said:
Hello,

I have some small code that opens a connection to an oledb-provider and
opens a recordset. Then creates a delegate to a RecordChangeComplete
event on the recordset.
When I put this code in a service (have tried both OnStart and in a
separate thread) I never get any RecordChangeComplete events. Although
using the exact same code in a form application the event works fine.
In both cases I can see that the oledb-provider is sending the right
events, but it seems they are trapped by the service somehow.

I have used the provider in services (written in C++) before, but never
using ADO / ADO.NET and it has always worked fine.

So what is ADO doing that behaves differently in a service-application
than in a Forms-application?

The code in the service looks like this:

protected override void OnStart(string[] args)
{
m_cn = new Connection();
m_rs = new Recordset();
m_cn.Open(Providerstring, "", "", 0);
m_rs.Open(Tablestring, m_cn, CursorTypeEnum.adOpenDynamic,
LockTypeEnum.adLockReadOnly, 0);
ADODB.RecordsetEvents_RecordChangeCompleteEventHandler
delRecordComplete = new
RecordsetEvents_RecordChangeCompleteEventHandler(RecordChangeComplete);
m_rs.RecordChangeComplete += delRecordComplete;
}

/Morgan L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top