How can I import Active Directory data into a SQL Server table using a query?

CREATE TABLE T_AD_Data
(
    lab_sAMAccountName varchar(100),
    lab_displayName varchar(100),
    lab_department varchar(100),
    lab_physicalDeliveryOfficeName varchar(100), 
);

INSERT INTO T_AD_Data
   SELECT * 
   FROM OpenQuery (ADSI,  
                   'SELECT sAMAccountName, displayName, department, physicalDeliveryOfficeName 
                    FROM ''LDAP://lab.com/DC=lab,DC=com'' 
                    WHERE objectClass =  ''User'' ') AS tblADSI

      

Mistake:

Msg 7330, Level 16, State 2, Line 1
Unable to get row from OLE DBprovider "ADSDSOObject" for linked server "ADSI"

+3


source to share


1 answer


I know this is a very old question, but the problem you are facing is caused by an ADSI query returning over 901 records. Until SQL 2008, this was not a problem, and the number of records was limited. But in SQL 2008 or later, when you hit that limit instead of truncated results, a runtime error occurs.



Work around this problem with some sort of lookup that uses multiple queries, like in my answer: fooobar.com/questions/1348061 / ...

0


source







All Articles