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



The information in this article applies to:

  • Microsoft SQL Server 2000 (all editions)

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),"urn:schemas:contacts:sn") LastName
FROM OpenQuery(Exchange,'SELECT "urn:schemas:contacts:sn"
FROM SCOPE(".\contacts")')
				
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), "urn:schemas:contacts:sn") LastName
	FROM OpenQuery(Exchange, 'SELECT "urn:schemas:contacts:sn" 
	FROM ".\Contact"')

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

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 "http://server/vroot/folder1"
				
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("http://server/vroot/folder1")
				
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:

REFERENCES

For more information on how to set up the linked server by using the OLE DB Provider for Exchange, see the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MajorLast Reviewed:10/3/2003
Keywords:kbBug kbprb kbProgramming KB300385