C#代码在控制台函数中工作,但在SQL CLR存储过程中不工作
请帮忙!!!我有一个从AD获取数据的代码。这在SQL2014/Visual Studio2013中使用。现在,我们正在迁移到SQL2016。我在一个控制台应用程序中测试了代码,效果很好。当我使用Visual Studio 2017将相同的代码创建到SQL CLR存储过程中时,它就不起作用了 这是Console应用程序中的代码:C#代码在控制台函数中工作,但在SQL CLR存储过程中不工作,c#,stored-procedures,sqlclr,C#,Stored Procedures,Sqlclr,请帮忙!!!我有一个从AD获取数据的代码。这在SQL2014/Visual Studio2013中使用。现在,我们正在迁移到SQL2016。我在一个控制台应用程序中测试了代码,效果很好。当我使用Visual Studio 2017将相同的代码创建到SQL CLR存储过程中时,它就不起作用了 这是Console应用程序中的代码: static void Main(string[] args) { DirectoryEntry ldapConn
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的值。当我在SQLCLR存储过程中放入相同的代码时,逻辑总是返回szErrorMessage值
我错过了什么
提前谢谢。最后。正如您之前正确指出的,bindDn是不正确的。问题是我们从一个DC转移到另一个DC。我用lip.exe找到了校长-userid@domain.com. 此外,不再需要ldapConnection.Path,因为新DC不正确。所以,最后,它是有效的。谢谢Clint。您缺少[Microsoft.SqlServer.Server.SqlProcedure],请再次检查target.netframework,并验证它在SQL2016Hi中是否受支持。Clint:我的CLR函数中已经有了它。公共部分类存储过程{[Microsoft.SqlServer.Server.SqlProcedure]公共静态void ValidateAD(字符串szNetworkID,out字符串szJDEID,out字符串szErrorMessage)此外,我将目标.net framework从4改为4.5改为4.7…尽管如此,存储过程仍无法正常工作。我还能找什么?你说同样的代码在SQL2014中工作,对吗?同样的代码在SQL2014中工作得非常好。这是正确的