请帮助!!!我有一个从AD获取数据的代码。这曾经在SQL2014 / Visual Studio2013中起作用。现在,我们正在迁移到SQL2016。我在控制台应用程序中测试了代码,并且工作正常。当我使用Visual Studio 2017在SQL CLR存储过程中创建相同的代码时,它只是不起作用。
这是控制台应用程序中的代码:
static void Main(string[] args)
{
DirectoryEntry ldapConnection;
DirectorySearcher search;
SearchResult result;
DirectoryEntry ldapconnection = null;
string szJDEID = "";
string szErrorMessage = "";
string szNetworkID = "xyz";
//--- Create and return new LDAP connection with desired settings
ldapConnection = new DirectoryEntry("LDAP://DC.company.com:389", "userid", "password");
ldapConnection.Path = "LDAP://DC=company,DC=com";
ldapConnection.AuthenticationType = AuthenticationTypes.Secure;
//--- create search object which operates on ldap connection object and set search object to only find the user specified
search = new DirectorySearcher(ldapconnection);
search.Filter = "(&(samaccountname=" + szNetworkID.Trim() + ")(memberOf=CN=JDEdwards Users,OU=Mail Enabled Manual,OU=Groups,OU=Global,DC=company,DC=com))";
result = search.FindOne();
if (result != null)
{
//--- create an array of properties that we would like and add them to the search object
string[] requiredproperties = new string[] { "extensionattribute13" };
foreach (string property in requiredproperties)
search.PropertiesToLoad.Add(property);
result = search.FindOne();
if (result != null)
{
foreach (string property in requiredproperties)
foreach (object mycollection in result.Properties[property])
szJDEID = mycollection.ToString();
}
}
else
{
szErrorMessage = "ERROR: This user does not belong to the JDEdwards Users AD Group. Please check with the IT Helpdesk team.";
}
}
我得到扩展属性13中存储的szJDEID的值。当我将相同的代码放入SQL CLR存储过程中时,逻辑总是返回szErrorMessage值。
我想念什么?
谢谢。
答案 0 :(得分:0)
最后。正如您之前正确指出的那样,bindDn是错误的。问题是我们从一个DC迁移到另一个DC。我使用lip.exe找出了主体-userid@domain.com。另外,不再需要ldapConnection.Path,因为新DC的ldapConnection.Path不正确。因此,最后,它正在工作。谢谢克林特。