Home All Groups Group Topic Archive Search About

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

Author
9 Dec 2004 12:41 PM
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

Author
9 Dec 2004 2:35 PM
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


Show quote
"ML" <s***@smeg.com> wrote in message
news:O%23GZwxe3EHA.936@TK2MSFTNGP12.phx.gbl...
> 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
>
Author
10 Dec 2004 10:21 AM
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



Show quote
"Sahil Malik" <contactmethrumyblog@nospam.com> wrote in message
news:%23MNUbxf3EHA.1188@tk2msftngp13.phx.gbl...
> 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" <s***@smeg.com> wrote in message
> news:O%23GZwxe3EHA.936@TK2MSFTNGP12.phx.gbl...
>> 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
>>
>
>
Author
27 Dec 2004 8:17 AM
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


Show quote
"ML" <s***@smeg.com> wrote in message
news:OaXxVIq3EHA.1264@TK2MSFTNGP12.phx.gbl...
>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" <contactmethrumyblog@nospam.com> wrote in message
> news:%23MNUbxf3EHA.1188@tk2msftngp13.phx.gbl...
>> 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" <s***@smeg.com> wrote in message
>> news:O%23GZwxe3EHA.936@TK2MSFTNGP12.phx.gbl...
>>> 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
>>>
>>
>>
>
>

AddThis Social Bookmark Button