[英]Get Active Directory GUID from SQL Server
I'm getting User GUID
from Active Directory in C#
using the code below: 我正在使用以下代码从C#
中的Active Directory获取User GUID
:
var GUIDID = "";
using (var domainContext = new PrincipalContext(ContextType.Domain, domain))
{
using (var user = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, userNameToUse))
{
if (user != null)
{
GUIDID = user.Guid.ToString();
}
}
}
So the output from the code above for a particular person is: 因此,上面的代码针对特定人员的输出为:
7b8b17f1-9997-46ac-bec4-c747eed2de33 7b8b17f1-9997-46ac-bec4-c747eed2de33
What I now want to do is query Active Directory from SQL Server 2008
using that GUIDID
. 我现在想做的是使用该GUIDID
从SQL Server 2008
查询Active Directory。 However, the issue I'm running into is I don't know the name of the column . 但是,我遇到的问题是我不知道该列的名称 。
I tried to search for the same person (using their full name) from SQL using the code below: 我尝试使用以下代码从SQL中搜索同一个人(使用其全名) :
SELECT cn, objectGUID
FROM 'LDAP://xxx.local/OU=xxx Users,DC=xxx,DC=xxx'
WHERE objectClass = 'User' AND cn = 'John Smith'
Yet, objectGUID
, OBjectSID
are not the same as the GUIDID
my C#
code is returning. 但是, objectGUID
, OBjectSID
与我的C#
代码返回的GUIDID
。
I also tried to select *
in my SQL
query, but it only returns the path. 我也尝试在SQL
查询中select *
,但它仅返回路径。
Any suggestion on how I can find out the GUID COLUMN name
from SQL Code? 关于如何从SQL代码中找出GUID COLUMN name
任何建议?
Thanks 谢谢
The solution is really simple. 解决方案非常简单。 I needed to convert the ObjectID
我需要转换ObjectID
SELECT CONVERT(UNIQUEIDENTIFIER,0xF1178B7B9799AC46BEC4C747EED2DE33);
Hope it helps somebody. 希望它能帮助到别人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.