
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