Microsoft KB Archive/300385

= PRB: Error 7321 When Executing a Select Statement to Query a Linked Server Using the Exchange OLE DB Provider =

Article ID: 300385

Article Last Modified on 10/3/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition

-



This article was previously published under Q300385





SYMPTOMS
You can create a linked server from SQL Server 2000 to Microsoft Exchange Server 2000, by using the OLE DB Provider for Exchange, and executing the following script: EXEC sp_addlinkedserver 'exchange', 'Exchange OLE DB provider', 'exoledb.DataSource.1', 'file:\\.\backofficestorage\localhost\public folders' You should be able to view the Tables (that is, the public folders) of the linked server from the SQL Enterprise Manager. However, if you query the public folders of the linked server by using the following SELECT statement Select Convert(nvarchar(200),&quot;urn:schemas:contacts:sn&quot;) LastName FROM OpenQuery(Exchange,'SELECT &quot;urn:schemas:contacts:sn&quot; FROM SCOPE(&quot;.\contacts&quot;)') you may receive the following error message:

Server: Msg 7321, Level 16, State 2, Line 1

An error occurred while preparing a query for execution against OLE DB provider 'exoledb.DataSource.1'.



CAUSE
Exchange Server's SCOPE uses deep traversal by default, which is not supported at a MAPI public folder.



WORKAROUND
To work around this problem, do either of the following:
 * Specify shallow traversal.
 * Do not use the keyword SCOPE, so that shallow traversal is chosen by default.

Use any of the following statements to retrieve correct results: SELECT Convert(nvarchar(30), &quot;urn:schemas:contacts:sn&quot;) LastName FROM OpenQuery(Exchange, 'SELECT &quot;urn:schemas:contacts:sn&quot;    FROM &quot;.\Contact&quot;')

SELECT Convert(nvarchar(30), &quot;urn:schemas:contacts:sn&quot;) LastName FROM OpenQuery(Exchange, 'SELECT &quot;urn:schemas:contacts:sn&quot;    FROM SCOPE(shallow traversal of &quot;.\Contact&quot;)')



MORE INFORMATION
A FROM clause does not require an explicit SCOPE element, in which case a shallow traversal is assumed, as in the following example: FROM &quot;http://server/vroot/folder1&quot; If a SCOPE element is specified in the SQL query statement, but a depth is not, the Microsoft Web Storage System query processor assumes a deep traversal, as in the following example: FROM SCOPE(&quot;http://server/vroot/folder1&quot;) The Web Storage System does not support deep traversals in the public information store that is designated for Messaging Application Programming Interface (MAPI) clients, such as Microsoft Outlook or Microsoft SQL Server. If either an explicit or implicit deep traversal is requested, the Web Storage System query processor returns an error.

For more information, see the following Microsoft Developer Network (MSDN) Web site:

http://msdn.microsoft.com/library/psdk/exchsv2k/_exch2k_the_basic_select_statement.htm