ADSI - 通过 SQL 服务器查询自定义用户属性失败

ADSI - Query Custom User Attribute through SQL Server Is Failing

我在 Active Directory 中创建了 4 个自定义属性。我按照此处的说明进行操作 - https://social.technet.microsoft.com/wiki/contents/articles/20319.how-to-create-a-custom-attribute-in-active-directory.aspx

我可以在 Active Directory Schema MMC(图 1)、AD 用户和计算机属性(图 2)中看到属性,并且可以 select 并使用 C# 和 PrincipalContext 更新这 4 个属性和 UserPrincipal(扩展)类。

几个月来我一直在使用这个 ADSI 查询...

SELECT * 
FROM OpenQuery (ADSI,  
                'SELECT SAMAccountName, pwdLastSet, lockoutTime, employeeID, displayName, givenname, sn, 
                        scriptpath, distinguishedName, telephoneNumber, mail, mobile,        
                        facsimileTelephoneNumber ,LastLogon, badPasswordTime, accountExpires, 
                        userAccountControl, manager
                 FROM ''LDAP://example.com/DC=example,DC=com'' 
                 WHERE objectClass =  ''User'' 
                   AND ''userAccountControl:1.2.840.113556.1.4.803:''<> 2') AS tblADSI_CBS
 WHERE 
     samaccountname not like '%$'

但是当我将 fBCArenaID 添加到查询中时,我收到了这条错误消息

Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "ADSDSOObject" for linked server "ADSI" reported an error. The provider did not give any information about the error.

Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider "ADSDSOObject" for linked server "ADSI".

问题:

图 1:我显示的自定义属性是 ADS MMC:

图 2:我在 AD 用户和计算机中显示的自定义属性:

我遇到了一个相同的问题——向 AD 添加了一个自定义字段('PreferredFirstName',在我的例子中),试图通过 ADSI 查询它,遇到错误 7350。我 运行 this discussion,其中提到了 sql 服务器中的模式缓存,因此我启动了一个新的 SQL 实例,将 ADSI 链接服务器添加到该新实例,查询立即运行/返回了我的自定义属性就好了。