Tracing Transactions
Sometimes, during development, or perhaps during deployment for logging purposes, you may want to trace the current transaction ID under which your object executes. COM+ provides you with two ways to retrieve the transaction ID, programmatically and administratively, using the Component Services Explorer.
To trace the current transaction ID programmatically, you should use
IObjectContextInfo::GetTransactionId( )
. Example 4-8
shows how to trace the current transaction ID to the output window in
the debugger.
Example 4-8. Tracing the current transaction ID to the output window
HRESULT hres = S_OK;
GUID guidTransactionID = GUID_NULL;
IObjectContextInfo* pObjectContextInfo = NULL;
hres = ::CoGetObjectContext(IID_IObjectContextInfo,
(void**)&pObjectContextInfo);
ASSERT(pObjectContextInfo != NULL); //a non-configure object maybe?
hres = pObjectContextInfo->GetTransactionId(&guidTransactionID);
pObjectContextInfo->Release( );
if(guidTransactionID == GUID_NULL)
{
ATLTRACE("The object does not take part in a transaction");
}
else
{
USES_CONVERSION;
WCHAR pwsGUID[150];
::StringFromGUID2(guidTransactionID,pwsGUID,150);
ATLTRACE("The object takes place in transaction with ID %s ",W2A(pwsGUID));
}As long as a transaction is in progress, you can view its transaction ID in the Component Services Explorer when using the administrative method. Under the My Computer icon in the Component Services Explorer is the Distributed Transaction Coordinator (DTC) folder. Expand the DTC ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access