C# 操作Windows Server 2003 AD域 常见异常与错误

原创 2011年01月26日 19:09:00

 

这个异常的原因是LDAP的path没有写正确  应该是域名的问题

System.DirectoryServices.DirectoryServicesCOMException was caught
  Message=从服务器返回了一个参照。

  Source=System.DirectoryServices
  ErrorCode=-2147016661
  ExtendedError=8235
  ExtendedErrorMessage=0000202B: RefErr: DSID-031006E0, data 0, 1 access points
    ref 1: 'bdxy'

  StackTrace:
       at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
       at System.DirectoryServices.DirectoryEntry.Bind()
       at System.DirectoryServices.DirectoryEntry.RefreshCache()
       at System.DirectoryServices.DirectoryEntry.FillCache(String propertyName)
       at System.DirectoryServices.PropertyCollection.KeysCollection.GetEnumerator()
       at WFAOPAD.ADForm.AccsesAD(String path, String account, String pwd) in D:/我的文档/Visual Studio 2010/Projects/wfaAD/WFAOPAD/ADForm.cs:line 30
  InnerException:



这个异常原因是LDAP的path没有写正确  应该是DN的问题
System.Runtime.InteropServices.COMException was caught
  Message=Unknown error (0x80005000)
  Source=System.DirectoryServices
  ErrorCode=-2147463168
  StackTrace:
       at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
       at System.DirectoryServices.DirectoryEntry.Bind()
       at System.DirectoryServices.DirectoryEntry.RefreshCache()
       at System.DirectoryServices.DirectoryEntry.FillCache(String propertyName)
       at System.DirectoryServices.PropertyCollection.KeysCollection.GetEnumerator()
       at WFAOPAD.ADForm.AccsesAD(String path, String account, String pwd) in D:/我的文档/Visual Studio 2010/Projects/wfaAD/WFAOPAD/ADForm.cs:line 30
  InnerException:



System.Reflection.TargetInvocationException was caught
  Message=Exception has been thrown by the target of an invocation.
  Source=System.DirectoryServices
  StackTrace:
       at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
       at WFAOPAD.ADForm.AddADAccount(String path, String account, String password, String addUser, String addPwd) in D:/我的文档/Visual Studio 2010/Projects/wfaAD/WFAOPAD/ADForm.cs:line 183
  InnerException: System.IO.FileNotFoundException
       Message=文件名、目录名或卷标语法不正确。 (Exception from HRESULT: 0x8007007B)
       Source=""
       InnerException:


端口号 异常的问题    解决方案 不要ad默认端口号  我觉得调用的不是默认端口号


这个异常的问题是 LDAP访问的path不对

System.DirectoryServices.DirectoryServicesCOMException was unhandled
  Message=在服务器上没有这样一个对象。 (Exception from HRESULT: 0x80072030)
  Source=System.DirectoryServices
  ErrorCode=-2147016656
  ExtendedError=8333
  ExtendedErrorMessage=0000208D: NameErr: DSID-031001CD, problem 2001 (NO_OBJECT), data 0, best match of:
    'CN=Users,DC=bdxy,DC=com'

  StackTrace:
       at System.DirectoryServices.DirectoryEntries.Find(String name, String schemaClassName)
       at WFAOPAD.ADForm.btnUse_Click(Object sender, EventArgs e) in D:/我的文档/Visual Studio 2010/Projects/wfaAD/WFAOPAD/ADForm.cs:line 230
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at WFAOPAD.Program.Main() in D:/我的文档/Visual Studio 2010/Projects/wfaAD/WFAOPAD/Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:


重命名语法的问题

System.DirectoryServices.DirectoryServicesCOMException was caught
  Message=指定了一个无效的 dn 语法。 (Exception from HRESULT: 0x80072032)
  Source=System.DirectoryServices
  ErrorCode=-2147016654
  ExtendedError=8335
  ExtendedErrorMessage=0000208F: NameErr: DSID-031001BA, problem 2006 (BAD_NAME), data 8350, best match of:
    '123456,OU=net,OU=jskf,OU=bdxyxx,DC=bdxy,DC=com'

  StackTrace:
       at System.DirectoryServices.DirectoryEntry.MoveTo(DirectoryEntry newParent, String newName)
       at System.DirectoryServices.DirectoryEntry.Rename(String newName)
       at OperateADLibrary.OperateAD.RenameUser(String oldUserName, String newUserName) in D:/我的文档/Visual Studio 2010/Projects/wfaAD/OperateADLibrary/OperateAD.cs:line 117
  InnerException:



密码不正确

System.Reflection.TargetInvocationException was caught
  Message=Exception has been thrown by the target of an invocation.
  Source=System.DirectoryServices
  StackTrace:
       at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
       at OperateADLibrary.OperateAD.ChangePassword(String username, String oldpwd, String newpwd) in D:/我的文档/Visual Studio 2010/Projects/wfaAD/OperateADLibrary/OperateAD.cs:line 180
  InnerException: System.Runtime.InteropServices.COMException
       Message=指定的网络密码不正确。 (Exception from HRESULT: 0x80070056)
       Source=""
       ErrorCode=-2147024810
       InnerException:

最后的一个总结是, 大部分的出错原因是LDAP的访问语法书写错误,而且很多的操作都在代码里体会就明白,和数据库的操作很类似。

 

用ldap方式访问AD域的的错误一般会如下格式:
LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece
其中红字部分的意思如下:
525 - 用户没有找到
52e - 证书不正确
530 - not permitted to logon at this time
532 - 密码期满
533 - 帐户不可用
701 - 账户期满
773 - 用户必须重设密码

LDAP常见错误对应编码表

LDAP_SUCCESS = 0 //成功LDAP_OPERATIONS_ERROR = 1 //操作错误LDAP_PROTOCOL_ERROR = 2 //协议错误LDAP_TIME_LIMIT_E...
  • pursue168
  • pursue168
  • 2011-05-19 20:45:00
  • 1307

DirectoryEntry配置IIS7出现ADSI Error:未知错误(0x80005000)

一、错误情况 环境:win7+iis7.0 DirectoryEntry配置IIS7出现如下错误 或者是 下面一段代码在IIS6.0下运转正常,但IIS7.0下运转会出错:   Sys...
  • Ts1030746080
  • Ts1030746080
  • 2013-03-30 23:54:10
  • 14611

使用DirectoryEntry进行 IIS 操作

public class IISAdmin {     #region  建IIS站点方法1 (缺点 不能启动站点)     //    public static int CreateW...
  • wu_qionglei
  • wu_qionglei
  • 2011-08-12 16:29:47
  • 3383

asp.net操作AD的问题

1、 在ASP.NET中, 启用Windows集成验证,这样我们就有了登陆网页的用户名和密码的哈希版本,但是我们是不能直接使用的,因为是密码的哈希版本,而不是密码本身。 比如: System.D...
  • cdefg198
  • cdefg198
  • 2012-10-17 17:21:40
  • 6123

LDAP error Code 及解决方法

   1.  error code 53===========================================================================问题:创建...
  • TechChan
  • TechChan
  • 2010-04-01 11:33:00
  • 56444

LDAP的特定错误

LDAP的特定错误 Error: com.macromedia.contribute.server.exception.DBException: Error in bind() from L...
  • zdwzzu2006
  • zdwzzu2006
  • 2013-01-28 23:43:01
  • 16168

常见LDAP错误

LDAP_SUCCESS = 0 //成功LDAP_OPERATIONS_ERROR = 1 //操作错误LDAP_PROTOCOL_ERROR = 2 //协议错误LDAP_TIME_LIMIT_E...
  • myanm
  • myanm
  • 2007-01-12 16:11:00
  • 4748

C# 操作Windows Server 2003 AD域 常见异常与错误

这个异常的原因是LDAP的path没有写正确  应该是域名的问题 System.DirectoryServices.DirectoryServicesCOMException was caugh...
  • wph_1129
  • wph_1129
  • 2011-01-26 19:09:00
  • 7400

出现一个操作错误 (An operations error occurred)

问题描述:  出现一个操作错误  An operations error occurred --> System.Runtime.InteropServices.COMException (0x8...
  • ceocyo
  • ceocyo
  • 2013-08-14 16:53:34
  • 505

Windows Server 2003域和集群

一、域和集群的介绍   “域”指的是服务器控制网络上的计算机能否加入的计算机组合。在”域“中的计算机可以访问共享资源。在“域”模式下,至少有一台服务器负责每一台联入网络的电脑和用户的验证工作,相当于...
  • qq_29721419
  • qq_29721419
  • 2016-10-18 15:24:02
  • 1755
收藏助手
不良信息举报
您举报文章:C# 操作Windows Server 2003 AD域 常见异常与错误
举报原因:
原因补充:

(最多只允许输入30个字)