Platform SDK: Exchange 2000 Server |
[This is preliminary documentation and subject to change.]
Returns the currently active ADO Connection object.
[Visual Basic,VBScript] Property ActiveConnection as ADODB.Connection [C++] HRESULT get_ActiveConnection(_Connection** pVal); HRESULT put_ActiveConnection(_Connection* Val); [IDL] HRESULT [propget] ActiveConnection([out,retval] _Connection** pVal); HRESULT [propput] ActiveConnection([in] _Connection* Val);
This property contains the _Connection interface on an ADO Connection object associated with the currently bound data source. This Connection exists only after directly binding the object to a data source specified using a URL (using an OLE DB 2.5 Provider) with calls to IDataSource.Open, IDataSource.SaveTo and IDataSource.SaveToContainer.
An ActiveConnection object reference is not available when the object is bound to another object after using IDataSource.OpenObject or SaveToObject, even if that object has an associated Connection object. Attempting to access the ActiveConnection property in such cases will cause the exception to be raised. For example, if you use IDataSource.OpenObject to bind a CDO object to an ADO Record object that is itself currently bound to an item in the Web Store or Active Directory, the Record object's Connection object is not available through the IDataSource.ActiveConnection property.
Dim iFldr As New Folder Dim iDsrc As CDO.IDataSource Set iDsrc = iFldr ' Open private root folder: ' e.g. URL1 = "file://./backofficestorage/microsoft.com/MBX2/useralias/" iDsrc.Open URL1, , adModeReadWrite Dim Conn As ADODB.Connection Set Conn = iDsrc.ActiveConnection Dim iMsg As New CDO.Message With iMsg .To = "someone@microsoft.com" .From = "another@microsoft.com" .Subject = "Here is the subject" .TextBody = "Here is the text of the message" End With Set iDsrc = iMsg iDsrc.SaveTo "MySavedItems/item8.eml", _ Conn, _ adModeReadWrite, _ adCreateOverwrite
HRESULT SaveMessageToDrafts(BSTR MailboxURL, IMessage* pMsg) { /* Assume these headers: * * #import <msado15.dll> no_namespace * #import <cdoex.dll> no_namespace * #include <iostream.h> * */ IDataSource* pDsrc = NULL; IDataSource* pDsrc2 = NULL; _Connection* pConn = NULL; HRESULT hr = CoCreateInstance(__uuidof(Folder), NULL, CLSCTX_INPROC_SERVER, __uuidof(IDataSource), reinterpret_cast<void**>(&pDsrc)); // for passing optional variants, we may need this _variant_t varOpt(DISP_E_PARAMNOTFOUND,VT_ERROR); /* * Bind to information store root folder (private/messages) * e.g. URL1 below is something like * "file://./backofficestorage/microsoft.com/storename/username/" * */ hr=pDsrc->raw_Open( MailboxURL, NULL, adModeRead, adFailIfNotExists, adOpenSource, NULL, NULL ); if(FAILED(hr)) { cerr << "Failed to open the specified Mailbox folder" << endl; goto exit; } /* * Get ActiveConnection for bound collection resource * (root of private folders for user) */ hr=pDsrc->get_ActiveConnection(&pConn); // Get IDataSource on passed message object. hr = pMsg->QueryInterface(__uuidof(IDataSource),(void**)&pDsrc2); /* * Save this message to some folder, e.g. * "MySavedItems/message8.eml" * ** Use the current connection used * ** to bind folder above */ hr = pDsrc2->raw_SaveTo( _bstr_t(MailboxURL) + _bstr_t("/Drafts/item8.eml"), (IDispatch*)pConn, //Connection from Folder Bind above adModeReadWrite, adCreateOverwrite, (RecordOpenOptionsEnum) NULL, NULL, NULL ); exit: pConn->Close(); pConn->Release(); pDsrc2->Release(); pDsrc->Release(); return hr;
Const adModeRead = 1 Const adModeReadWrite = 3 Const adCreateOverwrite = 67108864 Dim iFldr Set iFldr = CreateObject("CDO.Folder") Dim iDsrc Set iDsrc = iFldr ' Open private root folder: ' e.g. URL1 = "file://./backofficestorage/microsoft.com/MBX2/useralias/" iDsrc.Open URL1, , adModeReadWrite Dim Conn Set Conn = iDsrc.ActiveConnection Dim iMsg Set iMsg = CreateObject("CDO.Message") With iMsg .To = "someone@microsoft.com" .From = "another@microsoft.com" .Subject = "Here is the subject" .TextBody = "Here is the text of the message" End With Set iDsrc = iMsg iDsrc.SaveTo "MySavedItems/item8.eml", _ Conn, _ adModeReadWrite, _ adCreateOverwrite