由于单引号导致 LDAP 查询失败
我正在尝试使用以下 c# 代码在 Active Directory 中查找员工:
"Select userPrincipalName, ADsPath, Department, Mail,
HomeMDB, cn, ssn FROM
'LDAP://" + DomainName + "'
WHERE objectCategory = 'person' and
sAMAccountName = '" + UserName.Replace("'", "''") + "'";
当我为姓氏中带有单引号的员工(例如“O'Connor”)运行此代码时,我收到以下错误:
AdsDsoObject' 失败,没有可用的错误消息,结果代码:DB_E_NOTABLE(0x80040E37)。
I also tried Replace("'", "\''"), nothing is working.
我做错了什么? 需要帮忙。
谢谢你!
I'm trying to find an employee in Active Directory using the following c# code:
"Select userPrincipalName, ADsPath, Department, Mail,
HomeMDB, cn, ssn FROM
'LDAP://" + DomainName + "'
WHERE objectCategory = 'person' and
sAMAccountName = '" + UserName.Replace("'", "''") + "'";
When I run this for an employee with a single quote in the last name (such as "O'Connor") I get the following error:
AdsDsoObject' failed with no error message available, result code: DB_E_NOTABLE(0x80040E37).
I also tried Replace("'", "\''"), nothing is working.
What am I doing wrong? need help.
Thank You!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在它自己的线路上进行替换。
Do the replace on it's own line.
您尝试过:
而不是:(
其中有一个额外的单引号)。
You tried:
And not:
(There's an extra single quote in there).