Tải bản đầy đủ (.pdf) (54 trang)

Tài liệu Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (990.96 KB, 54 trang )








Contents
Overview 1
Examining the Universal Data Access
Strategy 2
Using ADO 2.5 to Access
Exchange 2000 Data 3
Building URLs to Access Resources 15
Using SQL Queries to Access
Exchange 2000 Data 21
Lab A: Accessing Exchange 2000 Data
Using ADO 36
Review 49

Module 3: Accessing
Exchange 2000 Data by
Using ADO 2.5


Information in this document is subject to change without notice. The names of companies,
products, people, characters, and/or data mentioned herein are fictitious and are in no way intended
to represent any real individual, company, product, or event, unless otherwise noted. Complying
with all applicable copyright laws is the responsibility of the user. No part of this document may
be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without the express written permission of Microsoft Corporation. If, however, your only


means of access is electronic, permission to print one copy is hereby granted.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.

 2000 Microsoft Corporation. All rights reserved.

Microsoft, Active Directory, ActiveX, FrontPage, Hotmail, JScript, MSN, Outlook, PowerPoint,
Visual Basic, Visual C++, Window Media, Visual InterDev, Visual Studio, Win32, Windows, and
Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the
U.S.A. and/or other countries.

Other product and company names mentioned herein may be the trademarks of their respective
owners.


Project Lead: Samantha Smith
Instructional Designers: Sangeeta Garg (NIIT (USA) Inc.), Marilyn McCune
Instructional Software Design Engineer: William Rebozo
Subject Matter Experts: Jayme Bowers (ECMS Inc.), John Christian (ECMS Inc.),
Robert Ginsburg (ECMS Inc.), Frederick Volking (ECMS Inc
Technical Contributors: Thomas Rizzo, Brent Ingraham, Navin Kachroo, Robert Brown,
Alex Hopmann, Jim Reitz
Graphic Artist: Kirsten Larson (S&T Consulting)
Editing Manager: Lynette Skinner
Editors: Kelly Baker, Nancy Finch
Copy Editor: Ed McKillop (S&T Consulting)
Production Manager: Miracle Davis

Print Coordinator: Marlene Lambert (Online Training Solutions Inc.)
Online Production Coordinator: Jenny Boe
Test Manager: Eric R. Myers
Creative Director, Media/Sim Services: David Mahlmann
Web Development Lead: Lisa Pease
CD Build Specialist: Eric Wagoner
Localization Manager: Rick Terek
Operations Coordinator: John Williams
Manufacturing Support: Laura King; Kathy Hershey
Lead Product Manager, Release Management: Bo Galford
Program Manager, Knowledge Management: Josh Barnhill
Lead Product Manager, Knowledge Management: Janet Wilson
Group Manager, Courseware Infrastructure: David Bramble
Director, Developer Training: Juan Fernando Rivera
General Manager: Robert Stewart

Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 iii


Instructor Notes
This module provides students with the information and describes the skills
necessary to use ActiveX
®
Data Objects (ADO) version 2.5, Structured Query
Language (SQL) queries, and URLs to access Microsoft
®
Exchange 2000
Server data and resources.
After completing this module, students will be able to:
!

Explain the concept of Microsoft Universal Data Access strategy.
!
Access data in Exchange 2000 by using the Connection, Recordset,
Record, and Stream objects.
!
Access resources in Exchange 2000 by using the File: and HTTP: schemes
and URLs.
!
Implement data searches in Exchange 2000 by using SQL statements.

Materials and Preparation
This section provides the materials and preparation tasks that you need to teach
this module.
Required Materials
To teach this module, you need the following materials:
!
Microsoft PowerPoint
®
file 2019A_03.ppt
!
Module 3, "Accessing Exchange 2000 Data by Using ADO 2.5"

Preparation Tasks
To prepare for this module, you should:
!
Read all of the materials for this module.
!
Complete the lab.
!
Read the Exchange 2000 Server Software Development Kit (SDK) material

related to ADO.

Presentation:
90 Minutes

Lab:
55 Minutes
iv Module 3: Accessing Exchange 2000 Data by Using ADO 2.5


Module Strategy
Use the following strategy to present this module:
!
Examining the Universal Data Access Strategy
Define Universal Data Access, and introduce open database connectivity
(ODBC), Remote Data Objects (RDO), Data Access Objects (DAO), and
the Microsoft Data Access Components (MDAC) that implement the
Universal Data Access strategy: OLE DB, ADO, RDS, and ODBC. At a
very high level, describe the interaction of OLE DB, ADO, and ODBC.
!
Using ADO 2.5 to Access Exchange 2000 Data
Present the standard and new ADO 2.5 objects, with emphasis on the
Record and Stream objects.
Use the code sample provided in Persisting a Recordset to discuss how to
save a Recordset as an Extensible Markup Language (XML) file.
Discuss how to use the Record object to perform record manipulation tasks,
such as creating files and folders, and copying, moving, and deleting
resources. Explain how to use the GetChildren method to access a user’s
mailbox, Contacts folder, and contacts by using the illustration in Using the
GetChildren Method to Navigate Web Storage System Data.

Explain how to use the Stream object to perform read/write operations on
files.
!
Building URLs to Access Resources
Explain how to use the File: and HTTP: schemes to access a resource.
Using the code samples provided in Using the File: and HTTP: Schemes,
explain how to use the schemes to access public stores and mailbox stores.
Explain the benefits of using HTTP: scheme over the File: scheme.
Introduce relative URLs and explain how to use relative URLs to move
through the hierarchical structure of the Web Storage System.
!
Using SQL Queries to Access Exchange 2000 Data
Present the SQL queries that are used to access Exchange 2000 data,
including the SCOPE SQL element, the WHERE clause, token formats,
and WHERE clause predicates.

Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 1


Overview
!
Examining the Universal Data Access Strategy
!
Using ADO 2.5 to Access Exchange 2000 Data
!
Building URLs to Access Resources
!
Using SQL Queries to Access Exchange 2000 Data



Microsoft
®
Exchange 2000 Server offers a host of database features that you
can take advantage of by using OLE DB and ActiveX
®
Data Objects (ADO)
version 2.5. Microsoft Universal Data Access strategy facilitates the use of the
OLE DB Provider for Exchange 2000 Server, which makes data in Exchange
2000 available to a collaborative application. You can write Structured Query
Language (SQL) statements to query the properties of resources in Exchange
2000 that are similar to queries that access relational databases. In addition, you
can use content indexing to search the content of standard text files and binary
files, such as Microsoft Word documents that are stored in Exchange 2000.
After completing this module, you will be able to:
!
Explain the concept of Universal Data Access strategy.
!
Access data in Exchange 2000 by using the Connection, Recordset,
Record, and Stream objects in ADO 2.5.
!
Access resources in Exchange 2000 by using the File: and HTTP: schemes
and relative URLs.
!
Implement data searches in Exchange 2000 by using SQL statements.

Topic Objective
To provide an overview of
the module topics and
objectives.
Lead-in

In this module, you will learn
about the Universal Data
Access strategy and how it
uses ADO 2.5 to access
data in Exchange 2000. You
will also learn how to use
URLs, and SQL queries to
gain access to Exchange
2000 data.
2 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5


Examining the Universal Data Access Strategy
Application Browser
OLE DB
Relational Data
Relational Data
SQL Server
SQL Server
Oracle
Oracle
Jet
Jet
Other
Other
FoxPro
FoxPro
Hierarchical Data
Hierarchical Data
Directory

Services
Directory
Services
Mail
Mail
Video
Video
Text
Text
Other
Other
Mainframe
and Legacy
Data
Mainframe
and Legacy
Data
ADO
ODBC


Universal Data Access is an operating environment, application, and tools
strategy for integrating diverse data sources (including relational and
hierarchical data sources) across an organization.
Support for Diverse Database Products
The components of the Universal Data Access strategy are tool- and language-
independent. These components do not require commitment to a single
vendor’s products, and they extend the functionality of well-known and well-
tested technologies including open database connectivity (ODBC), Remote
Data Objects (RDO), and Data Access Objects (DAO). Universal Data Access

support for open industry specifications means that you can provide solutions
by using the tools, applications, and operating environment services of your
choice.
Microsoft Data Access Components (MDAC) enables Universal Data Access.
The MDAC components include OLE DB, ADO, ODBC, and Remote Data
Service (RDS, formerly known as Advanced Database Connector, or ADC).

For more information about the current release of MDAC, you can view
the online documentation at

Interaction of OLE DB, ADO, and ODBC
OLE DB is a system-level programming interface to data across an
organization. ADO is an application programming interface (API) to OLE DB
data. OLE DB builds on the success of ODBC by providing an open standard
for accessing all types of data. Whereas ODBC was created to access relational
databases, OLE DB is designed for relational and hierarchical information
sources, including Microsoft SQL Server

, Oracle, mainframe ISAM/VSAM
(indexed sequential access method/virtual storage access method) and
hierarchical databases; e-mail and file system stores; text, graphical, and
geographical data; and custom business objects.
Topic Objective
To present the Universal
Data Access strategy.
Lead-in
The Universal Data Access
strategy uses Microsoft Data
Access Components
(MDAC) to access data.

These components include
OLE DB, ADO, RDS,
and ODBC.
Explain the concept of
Universal Data Access and
describe how developers
can use it to access a wide
range of data sources using
a common API. Explain how
the layers in the slide work
together.
Note
Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 3


#
##
#

Using ADO 2.5 to Access Exchange 2000 Data
!
Standard ADO 2.5 Objects
!
Persisting a Recordset
!
New ADO 2.5 Objects
!
Creating, Copying, and Deleting Resources Using the
Record Object
!

Using the GetChildren Method to Navigate Web Storage
System Data
!
Using the Stream Object


Although Microsoft Exchange version 5.5 is an effective store for mass
hierarchical data, developing applications for Exchange 5.5 requires the use of
either Collaboration Data Objects (CDO) version 1.2.1 or the Microsoft
Outlook
®
object model.
With the inclusion of the Web Storage System, Exchange 2000 excels at mass
storage, but now blends the Universal Data Access strategy with the exposure
to an OLE DB interface that can be accessed by using ADO version 2.5. You
can use the OLE DB Provider for Exchange on the local server to access Web
Storage System items by using OLE DB, ADO 2.5, and CDO.
The new ADO 2.5 Record and Stream objects facilitate access to hierarchical
data in the Web Storage System.
Topic Objective
To list the topics related to
using ADO 2.5 to access
Exchange 2000 data.
Lead-in
In this section, you will learn
how to use ADO 2.5 objects
to access data in
Exchange 2000.
4 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5



Standard ADO 2.5 Objects
!
Connection Object
$
Use to perform data operations
!
Recordset Object
$
Use to issue SQL SELECT statements
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ExOLEDB.DataSource"
conn.Open "http://servername/exchange/administrator/"
Set rs = CreateObject("ADODB.Recordset")
strSQL = "SELECT ""urn:schemas:mailheader:subject""
FROM" & _
"""http://servername/exchange/User1/inbox/""" & _
"WHERE ""DAV:ishidden"" = FALSE"
rs.Open strSQL, conn
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ExOLEDB.DataSource"
conn.Open "http://servername/exchange/administrator/"
Set rs = CreateObject("ADODB.Recordset")
strSQL = "SELECT ""urn:schemas:mailheader:subject""
FROM" & _
"""http://servername/exchange/User1/inbox/""" & _
"WHERE ""DAV:ishidden"" = FALSE"
rs.Open strSQL, conn



You can use the following ADO 2.5 objects to create applications that access
and modify data in the Web Storage System.
Connection Object
Use the ADO Connection object to bind to a particular public or mailbox store,
manage grouped operations, and share across Record and Recordset objects to
avoid continually rebinding to stores. When using the ADO Connection object
to access data in Exchange 2000, you must use OLE DB Provider for Exchange
by setting the Provider property to ExOLDB.DataSource. For example, the
following code example groups a set of data operations in Exchange 2000 in the
context of an OLE DB transaction:
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ExOLEDB.DataSource"
conn.Open "http://servername/public/"
conn.BeginTrans
'perform data operations
conn.CommitTrans

For best server-side performance, place Connection object references in ASP
Session or Application objects and reuse this connection from Active Server
Pages (ASP).
Topic Objective
To present the objects that
are standard to ADO.
Lead-in
The objects that are
standard in all versions of
ADO include the
Connection and
Recordset objects.
Explain how to set the

Provider property of a
Connection object to
access data in
Exchange 2000. Mention
that many of the methods
and their parameters are
used in the same way as
they would be used to
access relational databases
with ADO 2.1. Discuss the
security limitations of the
Connection object with
Exchange 2000 and briefly
mention how to implement
security by using COM+
applications.
Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 5


Recordset Object
The Recordset object represents the result of an executed command, usually a
set of records returned from a database query. You can navigate through a
recordset by using methods such as MoveNext and MovePrevious. You can
use the RecordCount property to determine the number of records in a
recordset. In addition, you can use the BOF (Beginning of File) and EOF (End
of File) properties to determine if the current record position is at the beginning
or end of a recordset. For example, the following code creates a recordset of all
the messages in an administrator’s Inbox, prints the total number of messages in
the Inbox, and then prints the subject of each message:
Set conn = CreateObject("ADODB.Connection")

conn.Provider = "ExOLEDB.DataSource"
conn.Open "http://servername/exchange/administrator/"
Set rs = CreateObject("ADODB.Recordset")
strSQL = "SELECT ""urn:schemas:mailheader:subject"" FROM" & _
"""http://servername/exchange/administrator/inbox/""" & _
"WHERE ""DAV:ishidden"" = FALSE"
rs.Open strSQL, conn
Debug.Print rs.RecordCount
Do Until rs.EOF = True
Debug.Print rs.Fields("urn:schemas:mailheader:subject")
rs.MoveNext
Loop


ADO exposes various properties and methods through the ADO objects.
Although OLE DB Provider for Exchange supports most of the ADO object
model functionality, it does not support features, such as impersonation by
using the UserName and Password parameters available on many ADO
methods, cursor type selection, record locking options, or nested transactions.

Note
6 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5


Persisting a Recordset
Exchange
Exchange
2000
2000
ADO Recordset

SQL Query
Save
C:\AdminisContacts.xml


You can store a Recordset object in a file by using the Save method. The
persistently stored file may exist on a local drive, on a network server, or as a
URL on a Web site. Later, the file can be restored with either the Open method
of the Recordset object or the Execute method of the Connection object.
You can store Recordset objects in the Microsoft proprietary Advanced Data
TableGram (ADTG) database format or the open Extensible Markup Language
(XML) format. The following code saves the URL and the name of each
contact in the administrator’s Contact folder as an XML file:
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ExOLEDB.DataSource"
conn.Open "http://servername/exchange/administrator/"
Set rs = CreateObject("ADODB.Recordset")
strSQL = "SELECT ""DAV:href""," & _
" ""urn:schemas:contacts:cn"" FROM" & _
" ""http://servername/exchange/administrator/Contacts/""" & _
" WHERE ""DAV:ishidden"" = FALSE"
rs.Open strSQL, conn
rs.Save "c:\AdminsContacts.xml", adPersistXML

Topic Objective
To outline the process of
saving an ADO recordset as
an XML file.
Lead-in
You can save an ADO

recordset in the ADTG
format, or the open
XML format.
Explain how you can persist
a recordset as an XML file.
Mention that, although this
is beneficial, you can often
generate your own XML file
by using a looping
statement for more control
over the structure of the
XML file that is generated.
Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 7


New ADO 2.5 Objects
!
Record Object
$
Use to gain full access to any resource in the Web
Storage System
!
Stream Object
$
Use to read, write, and manage the binary stream of
bytes that comprise a file or message


ADO 2.0 had a simple means of accessing information in data sources, such as
relational databases. However, a lot of information exists as messages in

electronic mail systems or as files in operating systems tables—rather than as
tables in databases. Use the ADO 2.5 Record and Stream objects to access
information stored in sources other than relational databases.
Record Object
Use the Record object to gain full access to any resource in the Web Storage
System, including a resource's set of properties and its associated stream. The
Record object can represent and manage data, such as folders and files in a file
system, or folders and messages in an e-mail system. A Record object can also
represent a row in a Recordset. You can bind an ADO Record object directly
to a resource in the Web Storage System by using a URL.
Topic Objective
To present the two objects
that are new to ADO 2.5,
and to describe
their function.
Lead-in
New ADO 2.5 objects are
Record and Stream.
Discuss the importance of
using the Record and
Stream objects when
accessing the wide range of
file types that can be stored
in Exchange 2000’s
hierarchical structure.
Explain each code example,
defining the syntax
and function.
8 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5



To bind a resource to a Record object, use the Open method. When you use the
Open method, you can specify a Mode parameter to control access rights to the
resource. For example, you can set the Mode parameter to adModeRead,
adModeReadWrite or adModeShareExclusive. The following code uses the
Record object to set the urn:schemas-microsoft-com:office:office#Author
property for the Week17.xls file to the value Paul West:
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ExOLEDB.DataSource"
conn.Open "http://servername/public/timecards/"
Dim rec As New ADODB.Record
rec.Open "http://servername/public/timecards/Week17.xls", _
conn, adModeReadWrite
rec.Fields("urn:schemas-microsoft-com:office:office#Author") _
= "Paul West"
rec.Fields.Update

Stream Object
Use the Stream object to represent the contents of a file. You can use the
Stream object to read and write file data in text or binary format.
To open a Stream object, use the Open method. When you use the Open
method, you can use either the adDefaultStream property of a Record object
or the Record object itself.
The following code shows how to open a Stream object by using the
adDefaultStream property and the Record object itself:
Set conn = CreateObject("ADODB.Connection")
Set rec = CreateObject("ADODB.Record")
Set strm = CreateObject("ADODB.Stream")
conn.Provider = "ExOLEDB.DataSource"
conn.Open "http://servername/public/ApprovedOrders/"

rec.Open _
"http://servername/public/ApprovedOrders/order23.xml", conn
Set strm = rec.Fields(adDefaultStream).Value
' or you can use an existing record object
Set strm2 = CreateObject("ADODB.Stream")
strm2.Open rec, adModeRead, adOpenStreamFromRecord

Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 9


Creating, Copying, and Deleting Resources Using the
Record Object
!
Creating Files and Folders
$
Use the CreateOptions parameter with the Open method
of the Record object
!
Copying and Moving Resources
$
Use the CopyRecord and MoveRecord methods of the
Record object
!
Deleting Resources
$
Use the DeleteRecord method of the Record object


In addition to using ADO to open resources in a Web Storage System, you can
also use ADO in Web Storage System applications to perform record

manipulation tasks, such as creating, copying, moving, and deleting resources.
Creating Files and Folders
You can use the Record object to create files and folders. The Open method of
the Record object uses the CreateOptions parameter to determine how to open
and create a file or a folder. The following table lists the values of the
CreateOptions parameter.
Enumeration Description

adCreateCollection Creates a new collection (folder) at a specified URL
instead of opening an existing collection.
adCreateNonCollection Creates a new Record at the URL specified.
adCreateOverwrite Creates a resource or collection at a specified URL and
overwrites any existing resource or collection.
adFailIfNotExists Opens a resource or collection and results in a run-time
error if a resource or collection does not exist.
adOpenIfExists Opens a resource or collection. No error is generated if
a resource or collection does not exist.

Topic Objective
To explain how to use the
Record object to perform
record manipulation tasks.
Lead-in
You can use the Record
object to create files and
folders, copy, move, and
delete resources in
Exchange 2000.
Discuss the options in the
CreateOptions enumeration.

Discuss each code example
and explain the syntax and
function.
10 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5


The following code uses the CreateOptions parameter to create a new collection
at a specified URL and overwrites an existing collection if it exists:
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ExOLEDB.DataSource"
conn.Open "http://servername/public/"
Set rec = CreateObject("ADODB.Record")
rec.Open "http://servername/public/MyNewFolder", _
conn, adModeReadWrite, adCreateCollection + adCreateOverwrite

Copying and Moving Resources
You can use the CopyRecord and MoveRecord methods of the Record object
to copy and move resources from one location to another. The CopyRecord
method copies a resource from one URL and creates a duplicate of the resource
at another URL. Although the MoveRecord method works the same way as the
CopyRecord method, the resource at the original URL is deleted after the
operation.
When copying or moving a resource, you can also determine whether to
overwrite an existing resource—if it already exists—by using the
adCopyOverWrite and adMoveOverWrite constants with the CopyRecord and
MoveRecord methods, respectively.
The following code uses the MoveRecord method to move a document from
one folder to another:
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ExOLEDB.DataSource"

conn.Open "http://servername/public/"
Set rec = CreateObject("ADODB.Record")
'because the MoveRecord method deletes the original
'resource after the operation, you must open the
'resource using the adModeReadWrite option
rec.Open _
"http://servername/public/FolderA/NewProducts.doc", _
conn, adModeReadWrite
rec.MoveRecord _
"http://servername/public/FolderA/NewProducts.doc", _
"http://servername/public/FolderB/NewProducts.doc" _
, , , adMoveOverWrite


If you perform a copy or move operation on a collection, all of its
children move with it.

Note
Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 11


Deleting Resources
You can use the DeleteRecord method of the Record object to delete a
resource in the Web Storage System. To use this method, open a record on the
resource to be deleted with read/write permissions. Then, call the DeleteRecord
method.
The following code uses the DeleteRecord method to delete a contact from the
administrator’s Inbox:
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ExOLEDB.DataSource"

conn.Open "http://servername/exchange/administrator/"
Dim rec As New ADODB.Record
rec.Open "http://servername/exchange/administrator/" & _
"Contacts/Paul West.eml", conn, adModeReadWrite
rec.DeleteRecord

12 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5


Using the GetChildren Method to Navigate Web Storage
System Data
Recordset
Recordset
Inbox
Inbox
Contacts
Contacts
Calendar
Calendar
Sent Items
Sent Items
Recordset
Recordset
Inbox
Inbox
Contacts
Contacts
Calendar
Calendar
Sent Items

Sent Items
Record
Record
Record
GetChildren()GetChildren()
Record
Record
Record
Mailbox 1


Information in the Web Storage System is distributed throughout a number of
databases for private and public stores. These databases, in turn, contain a
number of related tables. For instance, the Folders table keeps track of folders
while another table represents items in a folder.
A Recordset object represents each of these tables, and a Record object
represents an individual record, such as a folder or item. Because the Web
Storage System is based on a hierarchical database, folders and items can be
both Records and Recordsets. By using a combination of URLs and ADO
objects, you can access and control the contents of the Web Storage System.
Expanding a User’s Mailbox
In the illustration, Mailbox 1 is represented by an ADO Record object. By
calling the GetChildren method of the Record object, you are able to return all
of the immediate children records as a Recordset. Calling GetChildren from a
mailbox returns a Recordset containing the standard folders that are generated
whenever a mailbox is created (for example, Inbox, Contacts, Calendar, and
Sent Items).
Expanding a User’s Contact Folder
A Recordset consists of individual records; each folder is a record that can be
accessed independently. After returning a Contact folder as a record, you can

call the GetChildren method again to access all the contacts in the folder. Once
again a new Recordset is returned containing all the contacts in the folder. This
time, however, the resulting Recordset contains individual contacts.

Recordsets can contain multiple types of resources, such as folders,
items, structured documents, and files.

Topic Objective
To explain how to use the
GetChildren method to
access a user’s mailbox,
Contacts folder, and
contacts.
Lead-in
You can use the
GetChildren method to
traverse files and folders in
the Web Storage System.
Note
Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 13


Using the Stream Object
!
Accessing Files
$
Use the Type and Charset properties of the Stream
object
!
Reading from Files

$
Use the Read or the ReadText method of the Stream
object
!
Writing to Files
$
Use the Write or the WriteText method of the Stream
object


You can use a Stream object to access message attachments or files in
Exchange 2000. You can perform read/write operations on binary and standard
text files by using the Stream object.
Accessing Files
After you open a Stream object, you can manipulate the contents of the opened
file. First, specify the type of data in the file by setting the Type property. If the
file contains text data, specify the character set of the data in the file by using
the Charset property.
The Type property has an adTypeText default specifying that the file is a text
file. If you want to read or write binary data, you must set the Type property to
adTypeBinary. For text files, you can specify the Charset property by using a
string value. The default value of this property is “unicode” and it can be
changed to “ascii,” “iso-8858-1” or any other character set recognized in the
Microsoft Windows
®
2000 registry.
Reading from Files
To read the contents of a file, you can use the Read or the ReadText method.
!
Use the Read method to read data from a binary stream, such as what is

stored in a Microsoft Word document. Also, you can specify the number of
bytes to read.
!
Use the ReadText method to read the contents of a text file. You can
specify whether to read the whole file, a line, or a number of characters.
You can use the ReadText method only for forward operations; you cannot
move backward through a stream.

Topic Objective
To explain how to use the
Stream object to perform
read/write operations
on files.
Lead-in
Use a Stream object to
access message
attachments or files in
Exchange 2000.
Explain that the Record
object can be used to
access the properties of a
resource while the Stream
object is used to access the
text or binary contents of a
file. Walk through each code
example and explain the
syntax and function.
14 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5



The following code reads the contents of a text file into a text box:
rec.Open _
"http://servername/public/ApprovedOrders/Order23.xml", conn
strm.Open rec, adModeRead, adOpenStreamFromRecord
strm.Type = adTypeText
strm.Charset = "ascii"
txtOrder.Text = strm.ReadText(adReadAll)

Writing to Files
To write to a file, you can use the Write or the WriteText method.
!
Use the Write method to write to a binary stream.
!
Use the WriteText method to write to a text stream.

The following code shows how to write data to a text file:
strm.Open rec, adModeReadWrite, adOpenStreamFromRecord
strm.Type = adTypeText
strm.Charset = "ascii"
strm.WriteText txtOrder


Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 15


#
##
#

Building URLs to Access Resources

!
Using the File: and HTTP: Schemes
!
Benefits of Using the HTTP: Scheme
!
Using Relative URLs


Exchange 2000 introduces the use of URLs to name the objects in the Web
Storage System as an alternative to using connection strings and command text.
You can use URLs with the existing Connection and Recordset objects, and
with the new Record and Stream objects.
Topic Objective
To list the topics related to
building URLs to
access resources.
Lead-in
Using URLs to name Web
Storage System objects is
an alternative to using
connection strings and
command text.
16 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5


Using the File: and HTTP: Schemes
!
Using the File: Scheme
$
To access items in public folder trees, use:

file://./backofficestorage/domain-name/public-folder-
tree-name/path
$
To access a user’s base mailbox folder, use:
file://./backofficestorage/domain-name/MBX/user-
alias/path
!
Using the HTTP: Scheme
$
http://servername/virtual-directory/virtual-path


URL structure depends on whether you use the File: or HTTP: scheme. Also,
the URL that you use to address an item depends on the access protocol or
component that you use to access it. For example, you can use both File: and
HTTP: schemes to identify items and folders when using the server-side OLE
DB Provider for Exchange 2000, but you must use the HTTP: scheme when
addressing items that use the Hypertext Transfer Protocol/Web Distributed
Authoring and Versioning (HTTP/WebDAV) protocol.
Using the File: Scheme
When you construct URLs using the File: scheme for use with the OLE DB
Provider for Exchange, each URL has the following two forms:
!
A form to access items in Public Folder trees.
file://./backofficestorage/domain-name/public-folder-tree-
name/path

!
A form to access a user's mailbox folder.
file://./backofficestorage/domain-name/MBX/user-alias/path


For example, to bind a Record object to a resource named Report1.doc in the
public folder Reports in the domain contoso.msft, use the following File: URL:
Set rec = CreateObject("ADODB.Record")
rec.Open _
"file://./backofficestorage/contoso.msft/" & _
"public folders/reports/report1.doc"

Topic Objective
To present the syntax of the
File: scheme and the
HTTP: scheme.
Lead-in
When accessing resources
in the Web Storage System,
you can use the File:
scheme or the
HTTP: schemes.
Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 17


The following code binds a Record object to an appointment in an
administrator’s Calendar:
Set rec = CreateObject("ADODB.Record")
rec.Open "file://./backofficestorage/contoso.msft/" & _
"MBX/administrator/Calendar/Dentist.eml"


OLE DB Provider for Exchange registers the "File: OLE DB URL"
namespace with the OLE DB root binder. Therefore, you need not specify this

provider explicitly when you use OLE DB, ADO 2.5, or CDO for Exchange
2000 Server objects to access items by using the File: URL scheme.

Using the HTTP: Scheme
When you construct URLs by using the HTTP: scheme, you follow the same
procedure that you would use to access the item over the network by using the
HTTP protocol. The structure of the URL is as follows:
http://servername/virtual-directory/virtual-path

Notice the use of a virtual directory versus the File: scheme’s use of a default
folder tree name. The default virtual directory name for all private mailboxes in
any private store is "exchange". The default virtual directory name for public
folders, the top public folder in the default Public Folder tree, is "public".
The following are examples of URLs using the HTTP: scheme:
http://servername/public/reports/report1.doc
http://servername/exchange/administrator/Inbox/

When you use HTTP: schemes with the OLE DB Provider for Exchange, you
must specify the OLE DB Provider for Exchange binder when binding the item.
This provider has the programmatic identifier ExOLEDB.DataSource as shown
the following example:
Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "ExOLEDB.DataSource"
Conn.Open "http://servername/exchange/administrator/Inbox/"


The OLE DB Provider for Internet Publishing (MSDAIPP) is registered
as the default provider for the HTTP: scheme. If you do not specify the OLE
DB Provider for Exchange 2000, the MSDAIPP provider attempts to service the
request. This provider is not supported for use with CDO for Exchange 2000,

nor should it be used in server applications that need to scale.

Note
Discuss how the use of the
HTTP: scheme requires the
use of an explicit
Connection object whereas
the File: scheme does not.
Mention that the explicit use
of a Connection object has
benefits to lead into the next
section.
Note
18 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5


Benefits of Using the HTTP: Scheme
!
Transactions
$
Perform grouped data operations
!
Relative URLs
$
Traverse Exchange 2000 hierarchy
!
Errors
$
Retrieve ADO error information



When you explicitly create a Connection object by using the HTTP: scheme
for accessing resources and collections, you gain the following benefits, which
are not available when you use the File: scheme:
!
Transactions
You can perform multiple data operations in the context of an OLE DB
transaction to guarantee that they are all committed to the database, or that
they are all abort.

OLE DB transactions cannot be performed across multiple database
stores in Exchange 2000.

!
Relative URLs
You can reuse a Connection object and traverse the hierarchical structure of
Exchange 2000 databases by using relative URLs. You will learn more
about relative URLS in the next topic.
!
Errors
The Errors collection of the Connection object contains information about
any errors encountered during an ADO operation. You can use the
Description, Number, and Source properties of each Error object to
interpret error information.

Topic Objective
To present the benefits of
HTTP: scheme over
File: scheme.
Lead-in

The benefits of using HTTP:
scheme over File:
scheme are…
Make sure the students
understand what a
transaction is and how it
works. Also ensure that the
students are familiar with
the Errors collection and
the Error object.
Note
Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 19


Using Relative URLs
Administrator Mailbox
Inbox
Contacts
Calendar
agenda.eml
Hello.eml
rec.Open “../”, conn
rec.Open “./agenda.eml”, conn


When you explicitly establish a connection with Exchange 2000, you can use
relative URLs. A relative URL locates a resource relative to some starting point
defined by an absolute URL. For example, you can connect to a folder with the
following absolute URL:
http://servername/exchange/administrator/Inbox/


Navigating Down a Folder Hierarchy
You can then use a relative URL to access a child folder or item in that folder.
To navigate down the tree from this point, you build the relative URL that starts
with a dot and a forward slash (./), then append the remainder of the path to the
resource. For example, to access a message in the administrator’s Inbox, you
use the following relative URL:
./meeting agenda.eml

Navigating Up a Folder Hierarchy
You can also use relative URLs to move up the folder tree. To build a relative
URL for navigating up the tree, start the URL with two dots and a forward slash
(../), then append the remainder of the path to the resource. If you are moving
up the tree only one level, you use the following relative URL:
../

Topic Objective
To introduce relative URLs.
Lead-in
Relative URLs are used to
navigate the hierarchical
structure of the Web
Storage System.
Explain each code example
and describe the syntax
and function.
20 Module 3: Accessing Exchange 2000 Data by Using ADO 2.5


Example of Navigating a User’s Inbox

The following code shows how to use relative URLs with ADO. After
connecting to the administrator’s Inbox with an absolute URL, the code uses
relative URLs to navigate up and down the folder hierarchy.
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ExOLEDB.DataSource"
conn.Open "http://servername/exchange/administrator/Inbox/"
Set rec = CreateObject("ADODB.Record")
rec.Open "./meeting agenda.eml", conn
Debug.Print rec.Fields("DAV:href")
rec.Close
rec.Open "../", conn
Debug.Print rec.Fields("DAV:href")

Module 3: Accessing Exchange 2000 Data by Using ADO 2.5 21


#
##
#

Using SQL Queries to Access Exchange 2000 Data
!
The SQL SCOPE Element
!
Using the WHERE Clause
!
Matching Characters Using the LIKE Predicate
!
Attributing a Data Type to a Property Using the CAST
Predicate

!
Searching Text Using Content Indexing Predicates
!
Grouping and Ordering Query Results
!
Indexing Properties Using the CREATE INDEX Predicate


You can search for items in the Web Storage System by using familiar SQL
syntax, which is based on the syntax defined by the Microsoft Indexing Service
Query Processor.
The Microsoft Indexing Service search engine operates by using a system
account, which enables it to read all stores, including private mailboxes. To
maintain security, Rowset objects returned from an SQL query are evaluated
against the access control lists (ACLs) of the item or searched folder and the
security identifier of the user. Any row in which the Grant Access permission is
restricted is removed before the search result is returned.
Indexing properties and implementing full-text indexing improves search
performance.

The following properties are invalid in a search because their values are
calculated only when they are requested but not when they are searched upon:
DAV:lockdiscovery, DAV:resourcetype, and DAV:searchrequest.

Topic Objective
To list the topics related to
using SQL queries to
access Exchange 2000
data.
Lead-in

The Web Storage System
provides search capabilities
that use SQL syntax.
Note

×