Solved

MS SQL OpenQuery problem

Posted on 2013-05-30
4
578 Views
Last Modified: 2013-06-04
I have MS SQL 2012 installed on a W2K8 (64bit) server. I have a 'view' that queries Active Directory Users. I've attached the LinkServer setup and the OpenQuery view.

The view works fine when it is issued from the same server that the database is on. When I try to run it from another server I get an error. Here is the SQL statement I'm using:

select * from dbo.uvw_ActiveDirectoryUsersList

Here is the error I get:

Msg 7320, Level 16, State 2, Line 2
Cannot execute the query "SELECT samaccountname,
           givenName,
           sn,
           displayName,
           title,
           physicaldeliveryofficename,
           department,
           useraccountcontrol,
           profilepath
   FROM 'LDAP://OU=WCC Users,DC=wcc,DC=net'
   WHERE objectCategory = 'Person' AND
         objectClass = 'user'" against OLE DB provider "ADSDSOObject" for linked server "ADSI".

I have tried this using SSMS to connect remotely and from an application on a server that has only the SQL 2012 Native Client installed. I need to be able to run this query from an application server that has just the SQL 2012 Native Client installed, if possible.

BTW, I have domain admin privileges.

What am I missing?

Thanks in advance
OpenQuery.sql
LinkedServer.sql
0
Comment
Question by:softbreeze
  • 3
4 Comments
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 39208976
found this at http://www.sqlservercentral.com/Forums/Topic265745-149-1.aspx ...


SELECT * FROM OPENQUERY( [SERVER1],
'SELECT sAMAccountName, userPrincipalName, company, department, Name, givenName, SN, Mail, telephoneNumber, mobile,
l, physicalDeliveryOfficeName, postalCode, streetAddress, facsimileTelephoneNumber, msExchHideFromAddressLists, distinguishedName, info
FROM ''LDAP://SERVER1/ DC=subsubdomain,DC=subdomain,DC=domain''
WHERE
objectClass = ''user''
AND
objectCategory = ''Person''
AND (mobile = ''*'' OR telephoneNumber = ''*'' OR facsimileTelephoneNumber = ''*'' OR mail = ''*'' )
ORDER BY userPrincipalName
')

The difference lies in a space between "LDAP://SERVER1/" and "DC=subsubdomain,DC=subdom..."
and in the where clause. Don't know if that will make the difference?
0
 
LVL 1

Accepted Solution

by:
softbreeze earned 0 total points
ID: 39209005
Thanks but that isn't it. Remember this query works when run from the server where the database is.
0
 
LVL 1

Author Comment

by:softbreeze
ID: 39209076
I figured it out finally. I had to add a rmtuser and password to the sp_addlinkedserver statement:

EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'ADSI',
                                     @useself=N'True',                <--- N'False'
                                     @locallogin=NULL,
                                     @rmtuser=NULL,                 <--- N'wcc\wccadmin'
                                     @rmtpassword=NULL         <--- N'secretpassword'
0
 
LVL 1

Author Closing Comment

by:softbreeze
ID: 39218415
Even though I figured it out, you get the points for the quick reply that sent me in the right direction.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question