ATL Service and ADO Question... 
Author Message
 ATL Service and ADO Question...

Created an ATL Service that basically exposes a set of interfaces to clients
to interact with a database.  Choose ADO and had everything working fine.

Wanted to enable the resource pooling for ADO to try and speed things up a
bit.  So in the CServiceModule::Run I added the required code to create a
connection the backend db, when the message loop terminates I close the
connection.  This was done based on the information provided in the Article
"Pooling in the Microsoft Data Access Components"

"For an ADO-based consumer, by keeping one open instance of a Connection
object for each unique user and using the OLEDB_SERVICES connection string
attribute to enable or disable pooling. By default, ADO attempts to use
pooling, but if you do not keep at least one instance of a Connection object
open for each user, there will not be a persistent pool available to your
application. "

Now that I added that everything still works fine when the project is
running.  But the strange thing that keeps bothering me is that when the
service is shutdown if there are any outstanding interfaces held by clients
the destructors for those interfaces are never called.  And the debug window
fills up with leaks left and right.  Comment the Connection Open and close
and everything is back working fine(even with outstanding interfaces
CoUnitialize causes the destructor to be called.) but I loose the resource
pooling.  If there are no outstanding objects when the service terminates
then everything comes out just fine (no leaks). Does anyone have any good
ideas what might cause this?

Looks something like this...

...Normal ATL Service Wizard generated code...

hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER |
CLSCTX_REMOTE_SERVER, REGCLS_MULTIPLEUSE);
    _ASSERTE(SUCCEEDED(hr));

 LogEvent(_T("Service started"));

    if (m_bService)
        SetServiceStatus(SERVICE_RUNNING);

 ADODB::_ConnectionPtr pConnection;
 CREATEINSTANCE(pConnection,ADODB::Connection);
 pConnection->Open(DBConnect,"","",-1);

    MSG msg;
    while (GetMessage(&msg, 0, 0, 0))
        DispatchMessage(&msg);

    pConnection->Close();

 _Module.RevokeClassObjects();

..Normal ATL Service Wizard generated code.......

Thanks for any help you can provide.  I just can't understand why this is
happening.

jon



Sun, 27 Jun 2004 11:59:28 GMT  
 ATL Service and ADO Question...
You are not doing proper cleanup anyway. You should register
(via weak reference - no AddRef) each object you hand out in
an internal list. When terminating, call CoDisconnectObject on
all objects on the list. When an object terminates, it should
remove itself from the list. Use _Module.Lock/_Module.Unlock
to protect the list.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> Created an ATL Service that basically exposes a set of interfaces to clients
> to interact with a database.  Choose ADO and had everything working fine.

> Wanted to enable the resource pooling for ADO to try and speed things up a
> bit.  So in the CServiceModule::Run I added the required code to create a
> connection the backend db, when the message loop terminates I close the
> connection.  This was done based on the information provided in the Article
> "Pooling in the Microsoft Data Access Components"

> "For an ADO-based consumer, by keeping one open instance of a Connection
> object for each unique user and using the OLEDB_SERVICES connection string
> attribute to enable or disable pooling. By default, ADO attempts to use
> pooling, but if you do not keep at least one instance of a Connection object
> open for each user, there will not be a persistent pool available to your
> application. "

> Now that I added that everything still works fine when the project is
> running.  But the strange thing that keeps bothering me is that when the
> service is shutdown if there are any outstanding interfaces held by clients
> the destructors for those interfaces are never called.  And the debug window
> fills up with leaks left and right.  Comment the Connection Open and close
> and everything is back working fine(even with outstanding interfaces
> CoUnitialize causes the destructor to be called.) but I loose the resource
> pooling.  If there are no outstanding objects when the service terminates
> then everything comes out just fine (no leaks). Does anyone have any good
> ideas what might cause this?

> Looks something like this...

> ...Normal ATL Service Wizard generated code...

> hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER |
> CLSCTX_REMOTE_SERVER, REGCLS_MULTIPLEUSE);
>     _ASSERTE(SUCCEEDED(hr));

>  LogEvent(_T("Service started"));

>     if (m_bService)
>         SetServiceStatus(SERVICE_RUNNING);

>  ADODB::_ConnectionPtr pConnection;
>  CREATEINSTANCE(pConnection,ADODB::Connection);
>  pConnection->Open(DBConnect,"","",-1);

>     MSG msg;
>     while (GetMessage(&msg, 0, 0, 0))
>         DispatchMessage(&msg);

>     pConnection->Close();

>  _Module.RevokeClassObjects();

> ..Normal ATL Service Wizard generated code.......

> Thanks for any help you can provide.  I just can't understand why this is
> happening.

> jon



Mon, 28 Jun 2004 02:50:08 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Question regarding ADO with NT Services

2. ADO In ATL Project,ADO Version,CreateInstance Failed

3. Simple Question About ATL Service Wizard?

4. Simple ATL 7.0 Service question

5. ATL 7.0 NT Service question...

6. Question about ATL services, where to put user code

7. question for ATL Service

8. Quick question on message loop in ATL service

9. ATL service questions...

10. ATL service - amateur question

11. Additional ATL service question

12. ATL service question

 

 
Powered by phpBB® Forum Software