AccessViolationException bei Datenbankaufruf

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von blacky1974.

    AccessViolationException bei Datenbankaufruf

    Hallo,

    ich bekomme beim Aufruf der Datenbank nach einiger Zeit reproduzierbar in Zeile 19 eine AccessViolationException.

    Spoiler anzeigen

    Visual Basic-Quellcode

    1. [code]Private Sub DGV1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles _
    2. DGV1.CellEnter, DGV1.CellClick
    3. If e.RowIndex < 0 Then Exit Sub
    4. Try
    5. Dim PID As String = DGV1.Rows(e.RowIndex).Cells(0).Value
    6. Dim ORA1 As ADODB.Recordset
    7. Dim C_ID As Long = 0, PID1 As String, RE1 As String, PC1 As String, CN1 As String, CF1 As Boolean
    8. aktDGV = 1
    9. DGV2.Rows.Clear()
    10. sSQL = "t_master_dat WHERE PART_ID='" & PID & "'"
    11. ORA1 = New ADODB.Recordset
    12. ORA1.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
    13. ORA1.LockType = ADODB.LockTypeEnum.adLockOptimistic
    14. ORA1.Open(sSQL, ORAMain1, , , ADODB.CommandTypeEnum.adCmdTable)
    15. Do While Not ORA1.EOF
    16. C_ID = ORA1.Fields("C_ID").Value
    17. PID1 = ORA1.Fields("P_ID").Value
    18. RE1 = ORA1.Fields("P_VERSION").Value
    19. PC1 = ORA1.Fields("ACG_P_ID").Value
    20. CN1 = ""
    21. If Not IsDBNull(ORA1.Fields("ACG_NO").Value) Then CN1 = ORA1.Fields("ACG_NO").Value
    22. If ORA1.Fields("CUR_FLAG").Value = "y" Then CF1 = True Else CF1 = False
    23. 'CF1 = ORA.Fields("CUR_FLAG").Value
    24. DGV2.Rows.Add(C_ID, PID1, RE1, PC1, CN1, CF1)
    25. ORA1.MoveNext()
    26. Loop
    27. ORA1.Close()
    28. ORA1 = Nothing
    29. Catch ex As System.AccessViolationException
    30. MessageBox.Show(ex.Message)
    31. End Try
    32. End Sub



    Die Anwendung wurde ursprünglich in Visual Studio 2005 Net 2.0 für XP geschrieben. Dort ohne Fehler. Jetzt nach Umstellung auf Windows 7 wurde die Anwendung mit Visual Studio 2012 neu kompiliert. Nach einiger Zeit bekomme ich beim Click in das DataGridView eine Speicherveletzung (AccessViolationException)

    Ich vermute der Fehler liegt irgendwo anders. Leider kann ich mit den ErrorStack nicht viel anfangen.

    Spoiler anzeigen

    System.AccessViolationException wurde nicht behandelt.
    HResult=-2147467261
    Message=Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein Hinweis darauf, dass anderer Speicher beschädigt ist.
    Source=ADODB
    StackTrace:
    bei ADODB.RecordsetClass.Open(Object Source, Object ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType, Int32 Options)
    bei f5Format.Form2.DGV1_CellEnter(Object sender, DataGridViewCellEventArgs e) in ...\f5Format\Form2.vb:Zeile 72.
    bei System.Windows.Forms.DataGridView.OnCellEnter(DataGridViewCellEventArgs e)
    bei System.Windows.Forms.DataGridView.OnCellEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex)
    bei System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
    bei System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)
    bei System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
    bei System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
    bei System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
    bei System.Windows.Forms.Control.WndProc(Message& m)
    bei System.Windows.Forms.DataGridView.WndProc(Message& m)
    bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    bei System.Windows.Forms.Application.RunDialog(Form form)
    bei System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
    bei System.Windows.Forms.Form.ShowDialog()
    bei f5Format.Form1.CheckcsvBoM() in ...\f5Format\Form1.vb:Zeile 4679.
    bei f5Format.Form1.START_Click(Object sender, EventArgs e) in ...\f5Format\Form1.vb:Zeile 5149.
    bei System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
    bei System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
    bei System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
    bei System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
    bei System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
    bei System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
    bei System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
    bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    bei System.Windows.Forms.Control.WndProc(Message& m)
    bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    bei System.Windows.Forms.ToolStrip.WndProc(Message& m)
    bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    bei System.Windows.Forms.Application.Run(ApplicationContext context)
    bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    bei f5Format.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.
    bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    bei System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    bei System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
    bei System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
    bei System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
    bei System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
    bei System.Activator.CreateInstance(ActivationContext activationContext)
    bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
    bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    bei System.Threading.ThreadHelper.ThreadStart()
    InnerException:

    Kann mir bitte einer einen Tipp geben an welcher Stelle ich nach dem Fehler suchen muss.

    Danke :)
    Hallo,

    Danke für die Tipps...
    ORAMAIN1 wird in den beiden untenstehenden Funktionen definiert.
    Der Datenbankaufruf wird innerhalb der Anwendung mehrfach so ausgeführt und funktioniert in den übrigen Prozeduren. Leider kommt es in der oben genannten Prozedur in Zeile 19 immer wieder zum Fehler.

    Spoiler anzeigen

    Visual Basic-Quellcode

    1. Public Function ORASTRING(ByVal SS As String) As String
    2. SS = UCase(Trim(SS))
    3. ORASTRING = ""
    4. Dim ACC As ADODB.Recordset
    5. sSQL = "ORACLE_CONN WHERE ID='" & SS & "'"
    6. ACC = New ADODB.Recordset
    7. ACC.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
    8. ACC.LockType = ADODB.LockTypeEnum.adLockOptimistic
    9. ACC.Open(sSQL, ACCMain1, , , ADODB.CommandTypeEnum.adCmdTable)
    10. If ACC.RecordCount > 0 Then
    11. ORASTRING = "Provider=" & ACC.Fields("PROV").Value & _
    12. ";Password=" & ACC.Fields("PWD").Value & _
    13. ";Persist Security Info=True;User ID=" & ACC.Fields("APP").Value & _
    14. ";Data Source=" & ACC.Fields("DNS").Value
    15. End If
    16. ACC.Close() : ACC = Nothing
    17. End Function
    18. Public Function OpenORAbase1(ByVal DB_str As String) As Boolean
    19. Dim iI As Integer
    20. Dim strORAconnect As String = ORASTRING(DB_str)
    21. ORAMain1 = New ADODB.Connection
    22. ORAMain1.Open(strORAconnect)
    23. iI = ORAMain1.State
    24. If iI = 1 Then
    25. OpenORAbase1 = True
    26. Else
    27. OpenORAbase1 = False
    28. End If
    29. End Function



    Kann es damit zusammenhängen, das die beiden Funktionen in Form 1 definiert sind, aber der Aufruf der Prozedur die zum Fehler führt in Form 2 gespeichert ist? Da es Public Functions sind sollte das doch unerheblich sein. oder?

    Was kann man aus dem ErrorStack herauslesen? Steht jede Zeile für einen eigenen Fehler oder können das auch Folgefehler sein? Mir sagen diese Meldungen nichts.
    :)