请帮帮我!我有一个从AD获取数据的代码。这曾经在SQL2014/Visual Studio2013中起作用。现在,我们正在迁移到SQL2016。我在一个控制台应用程序中测试了代码,它工作得很好。当我使用Visual Studio 2017在SQL CLR存储过程中创建相同的代码时,它就不起作用了。
以下是控制台App中的代码:
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.";
}
}我得到了存储在扩展Attribute13中的szJDEID的值。当我将相同的代码放入SQL CLR存储过程中时,逻辑总是返回szErrorMessage值。
我遗漏了什么?
提前谢谢。
发布于 2020-02-19 20:34:07
终于来了。正如您之前正确指出的那样,bindDn是不正确的。问题是我们从一个DC移到了另一个DC。我使用lip.exe找出了主体- userid@domain.com。此外,不再需要ldapConnection.Path,因为它不适用于新的DC。所以,它终于起作用了。谢谢克林特。
https://stackoverflow.com/questions/60235517
复制相似问题