views:

14

answers:

0

Hi,

Within our system we have a linked server to our Active Directory server and a sql script which uses an LDAP query to retrieve users and groups in order to populate tables within an application.

This script worked without issue on the original set up (SQL 2005, Win Server '03 32 bit).

The script now will initially succeed (after taking much longer to execute - ~2-3 minutes vs ~20 seconds) on the new set up (SQL 2008, Win Server '08 64 bit) before consistently failing after several successful executions.

The code is basically:

SELECT  CAST(objectGUID AS UNIQUEIDENTIFIER ) AS GroupGUID, 
        [name] AS GroupName, 
        distinguishedname AS DN
FROM OPENQUERY (adsi, 
                'SELECT objectguid, name,distinguishedname
                 FROM ''LDAP://<ADSERVER>''
                 WHERE ObjectCategory=''group'' AND cn=''set_*''
                 ORDER BY cn')

to get a sub set of the groups (those beginning with "set_") and then loop through the groups using cursors to get all of the users in each of those groups, building up a sql query similar to:

SET @query =
            '
            SELECT  CAST(objectguid AS uniqueidentifier) AS UserGUID,
                        samaccountname AS UserName,
                        displayname AS Name,
                        mail AS Email,
                        useraccountcontrol
            FROM    OpenQuery(ADSI,  '' SELECT objectguid, samaccountname, mail, displayname, useraccountcontrol
                                        FROM ''''LDAP://<ADSERVER'''' 
                                        WHERE memberof=''''' + @dn + '''''
                                        AND (useraccountcontrol = blah OR useraccountcontrol = blah OR useraccountcontrol = blah)
                                        AND samaccountname >= ''''0*'''' AND samaccountname <= ''''9*'''' '')

with another two similar queries for samaccountnames between "a" and "l" then after "l".

The results are put into temp tables each iteration of the cursor and then dealt with accordingly.

Can anyone suggest what factors may cause this behaviour? i.e., working fine on old system but initially working before consistently failing on new system?

We're already looking into the infrastructure and have managed to count out any such differences there.

Any help or pointers would be greatly appreciated.

Thanks,

Robin

related questions