# Miscellaneous > SQL Scripts >  AddLinked Server (Exchange)  from SQL Server

## JamesRH

The syntax I am using is...



EXEC sp_addlinkedserver 'exchange', 
'Exchange OLE DB provider', 
'exoledb.DataSource.1',
'file:\\ServerMachine\M\ExchangeServer.LOCAL\PUBLI  C FOLDERS\backofficestorage\localhost\public folders'

Where the name of the machine is "ServerMachine".

The name of the domain, or Exchange Server is "ExchangeServer"

The path listed is a valid network path, and it is being executed as an Enterprise Administrator.

The problem is, when attempting to conntct, I get the error message...
"Error 7304: Could not create a new session on OLE DB Provider exoledb.datasource.1"

----------


## JBane

James,
I believe the Exchange server and the SQL server have to be on the same box.

See 'OLE DB Provider for Exchange' in BOL for details.

Jeff

----------


## JamesRH

They are on the same box...???

----------


## JBane

When you said you were using a unc path I thought you were pointing to a different machine.

----------


## JamesRH

I use the full path because I was initially testing from another machine, I also tested from the server that is running both services.  I also tried several variations of the path.  I was told by an friend that they don't need to be on the same box, but I did read that they did.  Anyway, do you have any suggestions??

Thanks James

----------


## JBane

James,
I'm not sure if you've tried this yet, but substitute your e-mail domain for 'localhost' in your string:

'backofficestorage\yourdomain.com\public folders'


Jeff

----------


## JamesRH

There is no DNS to this server, it is not an email server, and the domain name will not resolve to it.  It is on a LAN and not on the internet.  Also, Back office is not installed on it.  Exchange is only being used for contact management and calendering with Active Directory.  I have ruled out the possibility of it being permissions, I mapped permissions with sp_addlinkedsrvlogin and verified through testing.  

Here is the actual connection string I am trying with right now...

EXEC sp_addlinkedserver 'exchange', 'Exchange OLE DB provider', 'exoledb.DataSource.1', 'file:\\Skindisease\M\DERMFOUNDATION.LOCAL\PUBLIC FOLDERS'

I know that the first parameter is correct, and that the third parameter is correct (or so I think)  what I think is incorrect (my guess) is the path in the "file:\\..." there is not much documentation avaliable about this.  I tried using a "LDAP://" string as I found some references to this, but no sucess.  I am open to accessing this info from Active Directory if that is any easier?

----------


## JamesRH

I got the connection to Exchange to work.  I was correct about the part of the query that was in error.  the path must be "file:\\.\backofficestorage\" + the fully qualified domain name (servername.domain.com, in this case Dermfoundation.local) +"\public folders".  I don't know why this string started working now, when it didn't work before, but now I can see the tables (folders) in "public folders".  Now I am getting a different error message when trying to query the Contacts table (folder), "[Microsoft][ODBC SQL Server Driver][SQL Server] An error occured while prepairing a query for execution against OLE DB Provider 'Exoledb.datasource.1'".  

The query string is ...
SELECT Convert(nvarchar(30), "urn:schemas:contacts:sn") LastName
	FROM OpenQuery(Exchange, 'SELECT "urn:schemas:contacts:sn" 
	FROM ".\Contact"')

----------


## JamesRH

After I posted my last reply, I saw the error in my query, the last reference to the table was "Contact" and should have been "Contacts".  It works now....

----------

