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
Trang 1Building URLs to Access Resources 15
Using SQL Queries to Access
Trang 2to 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
Trang 3Instructor 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
Trang 4Module 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
Trang 5Overview
! 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
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
Trang 6Examining the Universal Data Access Strategy
Application Browser
OLE DB
Relational Data Relational Data
SQL Server Oracle Jet FoxPro Other
Hierarchical Data
Directory Services
Directory Services
Mail Video Text 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 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
language-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 http://www.microsoft.com/data/doc.htm
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
Trang 7# 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
Trang 8Standard ADO 2.5 Objects
! Connection Object
! Recordset Object
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" & _
strSQL = "SELECT ""urn:schemas:mailheader:subject"" FROM" & _
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
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
Trang 9Recordset 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
Trang 10Persisting a Recordset
Exchange 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
Trang 11New ADO 2.5 Objects
! Record Object
Storage System
! Stream Object
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
Trang 12To 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
Trang 13Creating, Copying, and Deleting Resources Using the
Record Object
! Creating Files and Folders
of the Record object
! Copying and Moving Resources
Record object
! Deleting Resources
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
instead of opening an existing collection
overwrites any existing resource or collection
error if a resource or collection does not exist
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
Trang 14The 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
Trang 15Deleting 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
Trang 16Using the GetChildren Method to Navigate Web Storage
System Data
Recordset
Inbox Contacts Calendar Sent Items
Recordset
Inbox Contacts
Calendar 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
Trang 17Using the Stream Object
! Accessing Files
object
! Reading from Files
object
! Writing to Files
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
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
Trang 18The 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
Trang 19# 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
Using URLs to name Web
Storage System objects is
an alternative to using
connection strings and
command text
Trang 20Using the File: and HTTP: Schemes
! Using the File: Scheme
tree-name/path
alias/path
file://./backofficestorage/domain-name/MBX/user-! 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
name/path
file://./backofficestorage/domain-name/public-folder-tree-! A form to access a user's mailbox folder
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
Trang 21The following code binds a Record object to an appointment in an
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
Trang 22Benefits of Using the HTTP: Scheme
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
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
Trang 23Using Relative URLs
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
Trang 24Example 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")
Trang 25# 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
The Web Storage System
provides search capabilities
that use SQL syntax
Note
Trang 26The SQL SCOPE Element
APPROVED ORDERS
ORDER23.xml ORDER24.xml ORDER25.xml
OLD ORDERS
ORDER1.xml ORDER2.xml ORDER3.xml
Defining a Search Scope by Using the SCOPE SQL Element
You define a search scope by using the SCOPE SQL element In the SCOPE
element, you define the depths of and URLs for the folders to be searched For shallow searches, you specify 'shallow traversal of'; for deep searches, you specify 'deep traversal of' After specifying the depth, you specify the URL for each folder The syntax for this statement is as follows:
SCOPE('shallow traversal of "URL1"',['shallow traversal of
"URL2"']) SCOPE('deep traversal of "URL1"', ['deep traversal of
"URL2"']) For example, to find all child folders in a particular folder, you execute the following SQL statement:
SELECT "DAV:href", "DAV:displayname"
FROM SCOPE('shallow traversal of "http://servername/public/"') WHERE "DAV:isfolder" = True and "DAV:ishidden" = False
This query returns all visible folders in the default public folder hierarchy The traversal is shallow, so subfolders are not searched
Topic Objective
To show how to scope
SQL searches
Lead-in
The SCOPE SQL element
can be used to define the
scope of a search
Explain the importance of
using SCOPE when
querying hierarchical data
structures Point out each
code example and explain
the syntax and function
Trang 27Default Behavior of the Scope Element
Use of the SCOPE element is optional If the element is not used, the search depth defaults to shallow traversal If you specify a SCOPE element but do not
specify a depth for a folder, the search default is a deep traversal For example, the following statement default is a shallow traversal:
SELECT "DAV:href" FROM "http://servername/public/surveys/" The following statement default is a deep traversal:
SELECT "DAV:href" FROM SCOPE('"http://servername/nonMAPIFolder/ApprovedOrders/"')
When specifying multiple folders in your SCOPE element, you must specify
the same depth for each folder You cannot mix deep and shallow searches in the same SQL command
Only shallow traversal of a single folder is supported in the Public Folder tree designated for MAPI clients If you specify deep traversal or multiple folders, an error is returned
Note