ADO Architecture
Topic Last Modified: 2006-06-12
The Microsoft® ActiveX® Data Objects (ADO) 2.5 object model is simple in design and has only a few objects. The following sections are a summary of the ADO objects most commonly used to access the Exchange store.
Use the ADO Connection object to bind to a particular public or private store, handle transactions, and share across Record and Recordset objects to avoid continually rebinding to stores. For example:
Dim Conn as New ADODB.Connection Conn.Provider = "ExOLEDB.DataSource" Conn.Open RootFolderURL Conn.BeginTrans Rec.Open ItemURL, Conn, adModeReadWrite ' .. Conn.CommitTrans ' .. Conn.Close Rec.Close Set Conn = Nothing Set Rec = Nothing
Placing Connection object references in ASP Session or Application objects and reusing this connection from one ASP page to another is ideal for optimal server-side performance.
You need a separate Connection object to bind to items in a different Exchange store mailbox store or public store. To avoid poor performance, you should reuse these Connection objects whenever possible. For example:
Dim Conn1 as New ADODB.Connection Dim Conn2 as New ADODB.Connection Dim Rec as New Record ' Assume /vroot1 is mapped to one public store and ' /vroot2 is mapped to another. Conn1.Provider="exoledb.datasource" Conn1.Open "http://servername/vroot1" Conn2.Provider="exoledb.datasource" Conn2.Open "http://servername/vroot2" Rec.Open "http://servername/vroot1/folder1/item.eml", Conn1, adModeReadWrite Rec.Close '... Rec.Open "http://servername/vroot_2/folder2/item2.eml", Conn2, adModeReadWrite
'... Conn1.Close Conn2.Close Rec.Close Set Conn1 = Nothing Set Conn2 = Nothing Set Rec = Nothing
Use the ADO Fields collection and the ADO Field object to access an item's properties. For example:
Dim Rec as New ADODB.Record Dim Conn as New ADODB.Connection Dim Flds as ADODB.Fields Dim Fld as ADODB.Field Dim Url As String Url = "http://server/public/test/item.eml" Conn.Provider = "ExOLEDB.DataSource" Conn.Open Url Rec.Open Url, Conn, adModeReadWrite Set Flds = Rec.Fields For Each Fld in Flds '... Next Fld ' ... Conn.Close Rec.Close Set Conn = Nothing Set Rec = Nothing
Use the Record object to access any item in the Exchange store. You have full access to the item's set of properties and its associated stream. For example:
Dim Rec As New ADODB.Record Dim Conn as New ADODB.Connection Dim Stm as ADODB.Stream Conn.Provider = "ExOLEDB.DataSource" Conn.Open "http://server/folder" Rec.Open "http://server/folder/item.txt", Conn Set Stm = Rec.Fields(adDefaultStream).Value '... Conn.Close Rec.Close Set Conn = Nothing Set Rec = Nothing
Use the Recordset object to issue Structured Query Language (SQL) SELECT commands in folders. For example:
Dim Conn as New ADODB.Connection
Dim Rs as New ADODB.Recordset
Conn.Provider = "ExOLEDB.DataSource"
Conn.Open RootFolderURL
Set Rs.ActiveConnection = Conn
"select ""DAV:displayname"" " _
& "from scope('shallow traversal of ""URL""')" _
& "Where ""DAV:ishidden"" = False"
'...
Conn.Close
Rs.Close
Set Conn = Nothing
Set Rs = Nothing
Use the ADO Stream object to access an item's stream. For example:
Dim Stm As ADODB.Stream Dim Rec as New ADODB.Record Dim Conn as New ADODB.Connection Dim Stm2 as New ADODB.Stream Dim Url As String Url = "http://server/public/item.txt" Conn.Provider = "ExOLEDB.DataSource" Conn.Open Url Rec.Open Url, Conn Set Stm = Rec.Fields(adDefaultStream).Value ' Or, alternately Stm2.Open Rec, adModeRead, adOpenStreamFromRecord '... Conn.Close Rec.Close Stm.Close Stm2.Close Set Conn = Nothing Set Rec = Nothing Set Stm = Nothing Set Stm2 = Nothing
Each of the following Collaboration Data Objects (CDO) objects provides an ADO Fields collection on its default interface, allowing you to access Exchange store item properties directly, as if the object was an ADO Record or Recordset object: