首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#代码在控制台函数中工作,但在SQL CLR存储过程中不工作

C#代码在控制台函数中工作,但在SQL CLR存储过程中不工作
EN

Stack Overflow用户
提问于 2020-02-15 10:26:58
回答 1查看 80关注 0票数 2

请帮帮我!我有一个从AD获取数据的代码。这曾经在SQL2014/Visual Studio2013中起作用。现在,我们正在迁移到SQL2016。我在一个控制台应用程序中测试了代码,它工作得很好。当我使用Visual Studio 2017在SQL CLR存储过程中创建相同的代码时,它就不起作用了。

以下是控制台App中的代码:

代码语言:javascript
复制
        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值。

我遗漏了什么?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-02-19 20:34:07

终于来了。正如您之前正确指出的那样,bindDn是不正确的。问题是我们从一个DC移到了另一个DC。我使用lip.exe找出了主体- userid@domain.com。此外,不再需要ldapConnection.Path,因为它不适用于新的DC。所以,它终于起作用了。谢谢克林特。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60235517

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档