?
Solved

MS SQL OpenQuery problem

Posted on 2013-05-30
4
Medium Priority
?
607 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

864 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