【发布时间】:2020-05-30 19:05:45
【问题描述】:
请帮忙!!!我有一个从 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.";
}
}
我得到了存储在 Extension Attribute13 中的 szJDEID 的值。当我将相同的代码放入 SQL CLR 存储过程中时,逻辑总是返回 szErrorMessage 值。
我错过了什么?
提前致谢。
【问题讨论】:
-
你缺少 [Microsoft.SqlServer.Server.SqlProcedure]
-
还要仔细检查您的目标 .netframework,并验证它是否在 SQL2016 中受支持
-
嗨 Clint:我的 CLR 函数中已经有了这个。 public partial class StoredProcedures { [Microsoft.SqlServer.Server.SqlProcedure] public static void ValidateAD(string szNetworkID, out string szJDEID, out string szErrorMessage) 另外,我将目标 .net 框架从 4 更改为 4.5 到 4.7 ...尽管如此在所有这些中,存储的过程不起作用。我还能寻找什么?
-
你说的代码在 SQL2014 中也能正常工作,对吧?
-
相同的代码在 SQL2014 中完美运行..这是正确的
标签: c# stored-procedures sqlclr