Solved

MS SQL OpenQuery problem

Posted on 2013-05-30
4
582 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL 2012 AOG and SQL2014 AOG 76 60
T-SQL Query - Group By Year 3 31
SQL Syntax 6 31
Need quicker response from an Execption table 11 23
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

749 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