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

 

这个异常的原因是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 - 用户必须重设密码

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
回答: 在C#操作SQL Server数据库可以使用ADO.NET来实现。根据提供的引用内容,可以看出在C#中执行SQL语句的方法是通过创建连接对象、命令对象和执行命令来实现的。首先,需要创建一个连接字符串,其中包含数据库的相关信息,如服务器名称、用户名、密码和数据库名称。引用\[1\]中的代码展示了如何创建一个连接对象并打开数据库连接。然后,可以创建一个命令对象,将要执行的SQL语句作为参数传递给命令对象。引用\[2\]中的代码展示了如何创建一个命令对象并执行SQL语句。在执行SQL语句时,可以使用ExecuteNonQuery方法来执行不返回结果集的SQL语句,如插入、更新和删除操作。如果执行过程中发生了异常,可以使用try-catch块来捕获并处理异常。引用\[1\]中的代码展示了如何处理SQL异常并显示错误消息框。最后,记得在使用完数据库连接后关闭连接,以释放资源。引用\[1\]中的代码展示了如何关闭数据库连接。需要注意的是,引用\[3\]中的代码展示了另一种连接字符串的写法,其中包含了服务器名称、用户名、密码和数据库名称。根据具体的情况,可以根据需要选择适合的连接字符串。 #### 引用[.reference_title] - *1* *2* [C#操作SQLServer数据库](https://blog.csdn.net/u014136513/article/details/50580553)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [C#操作SqlServer数据库,不积硅步无以至千里](https://blog.csdn.net/csklss/article/details/110121164)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值