【问题标题】:An unhandled exception of type 'System.AccessViolationException' occurred in System.DirectoryServices.dllSystem.DirectoryServices.dll 中出现“System.AccessViolationException”类型的未处理异常
【发布时间】:2016-07-03 05:05:49
【问题描述】:

我收到一个错误:

System.DirectoryServices.dll 中出现“System.AccessViolationException”类型的未处理异常

随机移动少数用户。

这很奇怪,它们发生的时间似乎没有押韵或原因,我有它在尝试中,但由于某种原因,最近它开始使应用程序崩溃。在调试器中,它们会弹出,您可以继续处理它们并完成线程,“失败”操作起作用,并在下一个周期重新运行移动。

If Action_Exe = "Update" Then
    If IsDBNull(Processing_DataResults.Rows.Item(Master_Loop)(16)) Then
        Trace.WriteLine("Error in datatable. NULL found.")
        Trace.WriteLine("Record: " & Master_Loop)
        Trace.WriteLine("User: " & Processing_DataResults.Rows.Item(Master_Loop)(1))
        Trace.WriteLine("AD Current Path: " & newUser.Path)
        'Update to try again
        CycleSQLQUERY.CommandText = "UPDATE [dbo].[AMS_Processing_Table] SET [Process_FLAG] = 3 WHERE [TrackingID] = '" & Processing_DataResults.Rows.Item(Master_Loop)(0).ToString & "';"
        WinEventLog.WriteEntry("Account Processing Thread: Null Var Found in Datatable. - " & Processing_DataResults.Rows.Item(Master_Loop)(1) & "-" & Master_Loop, EventLogEntryType.FailureAudit, 1614)
        Continue For
    End If
    Trace.WriteLine("OLD: " & Replace(newUser.Path, newUser.Name & ",", ""))
    Trace.WriteLine("New: " & LDAPSpecial & Replace(Processing_DataResults.Rows.Item(Master_Loop)(16), "/", "\/"))
    If LCase(Replace(newUser.Path, newUser.Name & ",", "")) <> LCase(LDAPSpecial & Replace(Processing_DataResults.Rows.Item(Master_Loop)(16), "/", "\/")) Then
        Thread.Sleep(100)
        Dim UserObjPath As String = newUser.Path
        Dim SuccessfulMove As Boolean = True
        Try
            newUser.MoveTo(New DirectoryEntry(LDAPSpecial & Replace(Processing_DataResults.Rows.Item(Master_Loop)(16), "/", "\/")))
        Catch CatchALL As Exception
            Trace.WriteLine(CatchALL.GetType)
            Trace.WriteLine("OLD: " & Replace(newUser.Path, newUser.Name & ",", ""))
            Trace.WriteLine("New: " & LDAPSpecial & Replace(Processing_DataResults.Rows.Item(Master_Loop)(16), "/", "\/"))
            WinEventLog.WriteEntry("Account Processing Thread: Failed to move user object in AD. - " & Processing_DataResults.Rows.Item(Master_Loop)(1) & " - " & CatchALL.Message & "; OLD: " & LCase(Replace(newUser.Path, newUser.Name & ",", "")) & "; NEW:" & LCase(LDAPSpecial & Replace(Processing_DataResults.Rows.Item(Master_Loop)(16), "/", "\/")), EventLogEntryType.FailureAudit, 1611)
            SuccessfulMove = False
            CycleSQLQUERY.CommandText = "UPDATE [dbo].[AMS_Processing_Table] SET [Process_FLAG] = 3 WHERE [TrackingID] = '" & Processing_DataResults.Rows.Item(Master_Loop)(0).ToString & "';"
            Try
                CycleSQLQUERY.ExecuteNonQuery()
            Catch ex_SQL As Exception
                'addin 5/3/16
            End Try
            Continue For
        End Try
        If SuccessfulMove = True Then

        Dim ChangeLineCount As Int64

任何建议、提示或修复将不胜感激。 这是一个多线程应用程序,尤其是这部分。我试图拨低线程数和同样的问题。

【问题讨论】:

  • 看来你不能加粗代码。我收到错误的位置在 newUser.MoveTo(New DirectoryEntry(LDAPSpecial & Replace(Processing_DataResults.Rows.Item(Master_Loop)(16), "/", "\/")))
  • 一个代码块是一个代码块是有原因的。 :)
  • 没有人吗? :-/ 好吧,我想我很高兴我不是唯一一个觉得困难的人。

标签: .net vb.net visual-studio-2013 active-directory


【解决方案1】:

所以,我找到了我的问题所在,以防其他人遇到这个问题。 发生的事情发生在我连接到 AD(仅使用域名)的代码的前面,如果操作是移动,它将运行上面的代码,创建与 AD 的新连接。当连接到活动目录时,它将选择一个可用的域控制器(所需的操作),如果 DC 出现故障,或者负载太大而无法处理额外的负载,这将很有帮助。 无论如何,第二个连接有时会连接到另一个 DC。当两个连接不在同一个 DC 上时,它会出错,很可能是因为更改尚未复制到该 DC,因为它们发生在不到一秒前。 所以,我对这个问题的解决方法是,我通过从 LDAP 中提取 dnshostname 并在第二个连接中使用它来加载第一个连接正在使用的 dc。

【讨论】:

    猜你喜欢
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 2020-07-22
    • 2014-06-03
    • 2011-10-18
    • 2014-03-09
    相关资源
    最近更新 更多