string ldapPath = "ldap://db.debian.org:389/uid=ma,ou=users,dc=debian,dc=org";
DirectoryEntry dEntry = new DirectoryEntry(ldapPath, null, null, AuthenticationTypes.Anonymous);
DirectorySearcher search = new DirectorySearcher(dEntry);
search.Filter = "((objectClass=*))";
search.FindAll();
我正在使用C#表单应用程序中的上述代码。每当我调用FindAll()时,我都会收到如下异常。
System.Runtime.InteropServices.COMException未处理
消息=“未知错误(0x80005000)”
Source =“System.DirectoryServices”ErrorCode = -2147463168
堆栈跟踪: 在System.DirectoryServices.DirectoryEntry.Bind(布尔值 throwIfFail) 在System.DirectoryServices.DirectoryEntry.Bind() 在System.DirectoryServices.DirectoryEntry.get_AdsObject() 在System.DirectoryServices.DirectorySearcher.FindAll(布尔值 findMoreThanOne) 在System.DirectoryServices.DirectorySearcher.FindAll() 在LDAPApp.Form1.button1_Click(Object sender,EventArgs e)中 H:\ Raj \ LDAP \ LDAPApp \ LDAPApp \ Form1.cs:第37行 在System.Windows.Forms.Control.OnClick(EventArgs e) 在System.Windows.Forms.Button.OnClick(EventArgs e) 在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 在System.Windows.Forms.Control.WmMouseUp(消息& m, MouseButtons按钮,Int32点击) 在System.Windows.Forms.Control.WndProc(消息& m) 在System.Windows.Forms.ButtonBase.WndProc(消息& m) 在System.Windows.Forms.Button.WndProc(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(的Int32 dwComponentID,Int32原因,Int32 pvLoopData) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(的Int32 原因,ApplicationContext上下文) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(的Int32 原因,ApplicationContext上下文) 在System.Windows.Forms.Application.Run(Form mainForm) 在LDAPApp.Program.Main()中 H:\ Raj \ LDAP \ LDAPApp \ LDAPApp \ Program.cs:第18行 在System.AppDomain._nExecuteAssembly(程序集, String [] args) 在System.AppDomain.ExecuteAssembly(String assemblyFile, 证据assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ThreadHelper.ThreadStart_Context(Object 州) 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态) 在System.Threading.ThreadHelper.ThreadStart()
的InnerException:
请告诉我这里我做错了什么。
提前致谢。
答案 0 :(得分:2)
LDAP路径中的LDAP协议标识符(LDAP://)必须为大写。 如果以小写形式编写LDAP协议标识符,则会出现0x80005000错误 代码(未知错误)。以下代码段应该有效:
string ldapPath = "LDAP://db.debian.org:389/uid=ma,ou=users,dc=debian,dc=org";
DirectoryEntry dEntry = new DirectoryEntry(ldapPath, null, null, AuthenticationTypes.Anonymous);
DirectorySearcher search = new DirectorySearcher(dEntry);
search.Filter = "((objectClass=*))";
search.FindAll();
希望,这有帮助。