Solved

MS SQL OpenQuery problem

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now