2016-07-03 39 views
-1

我得到一個錯誤:型「System.AccessViolationException」未處理的異常發生在System.DirectoryServices.dll程序

An unhandled exception of type 'System.AccessViolationException' occurred in System.DirectoryServices.dll

隨機地在移動用戶屈指可數。

奇怪的是,似乎沒有任何押韻或理由說明它們何時發生,我在TRY中試過,最近因爲某種原因它開始崩潰應用程序。在調試器中,它們彈出,您可以繼續完成它們並完成線程,「失敗」操作工作,並在下一個週期重新運行移動。

< --Code剪斷了 - >

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 

任何不過,建議,提示,或修復將不勝感激。 這是一個多線程應用程序,特別是這個部分。我試圖撥出線程數量和相同的問題。

+0

看來你不能大膽的代碼。我得到錯誤的位置在** newUser.MoveTo(New DirectoryEntry(LDAPSpecial&Replace(Processing_DataResults.Rows.Item(Master_Loop)(16),「/」,「\ /」)))** –

+0

代碼塊是一個原因的代碼塊。 :) –

+0

沒有人? : -/ 好吧,我想我很高興我不是唯一一個發現它很困難的人。 –

回答

0

因此,我發現我的問題是什麼,因爲任何人都會遇到這個問題。 發生了什麼是我在代碼中稍後在代碼中連接到AD的代碼的早期版本,如果該操作是移動它將運行上面的代碼,創建一個到AD的新連接。當連接到活動目錄時,它將選擇一個可用的域控制器(所需的操作),如果DC發生故障或者負載太大以至於無法處理額外負載時,這是有用的。 反正第二個連接有時會連接到另一個DC。當兩個連接都不在同一個DC上時,它會出錯,很可能是因爲這些更改沒有複製到該DC,因爲它們剛剛發生在不到一秒之前。 所以,我的問題的解決方法是我加載第一個連接所使用的dc,方法是從LDAP中拉出dnshostname,然後在第二個連接中使用它。

相關問題