[英]C# code works from Console function but does not work in SQL CLR Stored Procedure
PLEASE HELP!!!请帮忙!!! I have a code to get data from AD.
我有一个从 AD 获取数据的代码。 This used to work in SQL2014/Visual Studio2013.
这曾经在 SQL2014/Visual Studio2013 中工作。 Now, we are migrating to SQL2016.
现在,我们正在迁移到 SQL2016。 I tested the code in a Console App and it worked just fine.
我在控制台应用程序中测试了代码,它工作得很好。 It just does not work when I create the same code into a SQL CLR Stored Proc using Visual Studio 2017.
当我使用 Visual Studio 2017 在 SQL CLR 存储过程中创建相同的代码时,它不起作用。
This is the code in the Console 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.";
}
}
I get the value of szJDEID as stored in Extension Attribute13.我得到了存储在扩展属性 13 中的 szJDEID 的值。 When I put the same code in a SQL CLR Stored Proc, the Logic always returns the szErrorMessage value.
当我将相同的代码放在 SQL CLR 存储过程中时,逻辑总是返回 szErrorMessage 值。
What am I missing?我错过了什么?
Thanks in advance.提前致谢。
Finally.最后。 As you had rightly pointed earlier, the bindDn was incorrect.
正如您之前正确指出的那样, bindDn 是不正确的。 The issue is we moved from one DC to another.
问题是我们从一个 DC 搬到了另一个 DC。 I used lip.exe to find out the principal - userid@domain.com.
我使用 lip.exe 找出主体 - userid@domain.com。 Also, the ldapConnection.Path was not needed anymore as it was incorrect with the new DC.
此外,不再需要 ldapConnection.Path,因为它对新 DC 不正确。 So, finally, it is working.
所以,最后,它正在工作。 Thanks Clint.
谢谢克林特。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.