none
Problem disposing memory (attempted to read or write...) (Solved) RRS feed

  • Question

  • Well, Good day.

    I start this new post to ask for some help. As title states, I am dealing with this weird error for a second time. In the first one, I found a solution to trace back the trouble code (just be sure to keep checked not administrative code debugging in the project setup page). Right now I have some problems when dealing with savedialog and overwriting in special circunstances.

    If I save with no same named file, everything goes ok.

    If i save with same named file, everything goes OK JUST if I didnt run savefiledialog before. I mean that if I run the prog, and click on the save button, everything will go smoothly, even if file is present.

    In the other way, if I had saved before and plans to save again, with that same sequence, crash happens, wether file is present or not. As it is currently driving me mad, now I am requesting for help. Maybe someone could find where the problem is; maybe a table keeps open or whatever.

    I have found that problem is when accesing the reflection part of the code, so I update post to relfect that.

    Tried tons of combinations, with disposal and without them. Actually, this is the most stable code, although it keeps failing where noted:

     Public Sub Save()
    
    
    
    
    
    
    
     'Declare a SaveFileDialog object
    
    
    
    
    
    
    
     Dim objSaveFileDialog As New SaveFileDialog
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
     'Set the Save dialog properties
    
    
    
    
    
    
    
     With objSaveFileDialog
    
    
    
    
    
    
    
     .DefaultExt = "cvc"
    
    
    
    
    
    
    
     .FileName = "Test Document"
    
    
    
    
    
    
    
     .Filter = "Convac files (*.cvc)|*.cvc|All files (*.*)|*.*"
    
    
    
    
    
    
    
     .FilterIndex = 1
    
    
    
    
    
    
    
     .OverwritePrompt = True
    
    
    
    
    
    
    
     .Title = "Save File Dialog"
    
    
    
    
    
    
    
     End With
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
     'Show the Save dialog and if the user clicks the Save button,
    
    
    
    
    
    
    
     'save the file
    
    
    
    
    
    
    
     If objSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
    
    
    
    
    
    
    
     Dim filePath As String
    
    
    
    
    
    
    
     Dim Path As String
    
    
    
    
    
    
    
     Path = System.Reflection.Assembly.GetExecutingAssembly.Location
    
    
    
    
    
    
    
     Path = Replace(Path, "Ensayo.exe", "")
    
    
    
    'Locating where the program is being executed
    
    
    
     filePath = System.IO.Path.Combine( _
    
    
    
    
    
    
    
     My.Computer.FileSystem.SpecialDirectories.MyDocuments, _
    
    
    
    
    
    
    
     objSaveFileDialog.FileName)
    
    
    
    'Grabbing path to a public variable to be used later
    
    
    
     SavePath = filePath
    
    
    
    
    
    
    
     SavingSplash.Show()
    
    
    
    'Launching splash window showing progress
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Guardando..."
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Saving..."
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     ProgressBarValue = 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     If File.Exists(filePath) Then
    
    
    
    
    
    
    
     If File.Exists(Replace(filePath, ".cvc", ".bak")) Then
    
    
    
    
    
    
    
     File.Delete(Replace(filePath, ".cvc", ".bak"))
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     File.Move(filePath, Replace(filePath, ".cvc", ".bak"))
    
    
    
    
    
    
    
     End If
    
    
    
    'Cheching whether file is present or not, delete backup if also a bak file is present and replace with newer
    
    
    
     End If
    
    
    
    
    
    
    
     File.Copy("" & Path & "BDs\SaveFile", filePath)
    
    
    
    
    
    'Copy master save file
     Do
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     Loop Until File.Exists(filePath)
    
    
    
    'Wait until file is created
    
    
    
     Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " & filePath & ";Persist Security Info = False;"
    
    
    
    'Stablish connection string
    
    
    
     Try
    
    
    
    
    
    
    
     'Open or Create the file
    
    
    
    
    
    
    
     Using conConn As New OleDb.OleDbConnection(strConn)
    
    
    
    
    
    
    
     'CREAMOS EL STRING DE CONEXION
    
    
    
    
    
    
    
     strCom = "CREATE TABLE Backend ([VariableName] TEXT(50), [VariableValue] TEXT(50))"
    
    
    
    'Creating table on empty access database
    
    
    
     'CREAMOS EL OBJETO COMANDO
    
    
    
    
    
    
    
     Dim comando As New OleDb.OleDbCommand(strCom)
    
    
    
    
    
    
    
     comando.Connection = conConn
    
    
    
    
    
    
    
     conConn.Open()
    
    
    
    
    
    
    
     comando.ExecuteNonQuery()
    
    
    
    
    
    
    
     conConn.Close()
    
    
    
    
    
    
    
     End Using
    
    
    
    
    
    
    
     Using conConn As New OleDb.OleDbConnection(strConn)
    
    
    
    
    
    
    
     'CREAMOS EL STRING DE CONEXION
    
    
    
    
    
    
    
     strCom = "CREATE TABLE SpecialVariables ([VariableName] TEXT(200), [VariableValue] TEXT(200))"
    
    
    
    
    
    
    
     'CREAMOS EL OBJETO COMANDO
    
    
    
    
    
    
    
     Dim comando As New OleDb.OleDbCommand(strCom)
    
    
    
    
    
    
    
     comando.Connection = conConn
    
    
    
    
    
    
    
     conConn.Open()
    
    
    
    
    
    
    
     comando.ExecuteNonQuery()
    
    
    
    
    
    
    
     conConn.Close()
    
    
    
    
    
    
    
     End Using
    
    
    
    
    
    
    
     Using conConn As New OleDb.OleDbConnection(strConn)
    
    
    
    
    
    
    
     'CREAMOS EL STRING DE CONEXION
    
    
    
    
    
    
    
     strCom = "CREATE TABLE BackendVars ([VariableName] TEXT(50), [VariableValue] TEXT(50))"
    
    
    
    
    
    
    
     'CREAMOS EL OBJETO COMANDO
    
    
    
    
    
    
    
     Dim comando As New OleDb.OleDbCommand(strCom)
    
    
    
    
    
    
    
     comando.Connection = conConn
    
    
    
    
    
    
    
     conConn.Open()
    
    
    
    
    
    
    
     comando.ExecuteNonQuery()
    
    
    
    
    
    
    
     conConn.Close()
    
    
    
    
    
    
    
     End Using
    
    
    
    'Beginning to catch variables in special module
    
    
    
     Dim SpecialVarName As String
    
    
    
    
    
    
    
     Dim SpecialVarValue As String
    
    
    
    
    
    
    
     Dim Assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
    
    
    
    
    
    
    
     Dim Modul1 As Type
    
    
    
    
    
    
    
     Dim module1Field As System.Reflection.FieldInfo
    
    
    
    
    
    
    
     Modul1 = Assembly.GetType("Ensayo.PublicStrings")
    
    
    
    
    
    
    
     Dim PublicStringsTable As DataTable
    
    
    
    
    
    
    
     PublicStringsTable = New DataTable("GlobalVariables")
    
    
    
    'Creating new memory datatable to store variables
    
    
    
     Dim TableNewRow As DataRow
    
    
    
    
    
    
    
     Dim VariableName As DataColumn = New DataColumn("VariableName")
    
    
    
    
    
    
    
     VariableName.DataType = System.Type.GetType("System.String")
    
    
    
    
    
    
    
     PublicStringsTable.Columns.Add(VariableName)
    
    
    
    
    
    
    
     Dim VariableValue As DataColumn = New DataColumn("VariableValue")
    
    
    
    
    
    
    
     VariableValue.DataType = System.Type.GetType("System.String")
    
    
    
    
    
    
    
     PublicStringsTable.Columns.Add(VariableValue)
    
    
    
    'Define datatable estructure
    
    
    
     For Each module1Field In Modul1.GetFields
    
    
    
    'Begins loop, identify variable, copy name and value
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Recopilando variables globales...(" & ProgressBarValue & " registros totales guardados)"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Gathering global variables...(" & ProgressBarValue & " total saved entries)"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     SpecialVarName = module1Field.Name
    
    
    
    
    
    
    
     SpecialVarValue = module1Field.GetValue(module1Field)
    
    
    
    
    
    
    
     TableNewRow = PublicStringsTable.NewRow
    
    
    
    'Add such variable to datatable
    
    
    
     TableNewRow.Item("VariableName") = "" & SpecialVarName & ""
    
    
    
    
    
    
    
     TableNewRow.Item("VariableValue") = "" & SpecialVarValue & ""
    
    
    
    
    
    
    
     PublicStringsTable.Rows.Add(TableNewRow)
    
    
    
    
    
    
    
     Next
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Guardando variables globales..."
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Saving global variables..."
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     Dim DatatableIsOpen As Boolean
    
    
    
    
    
    
    
     Using conConn As New OleDb.OleDbConnection(strConn)
    
    
    
    
    
    
    
     For Each TableNewRow In PublicStringsTable.Rows
    
    
    
    
    
    
    
     If InStr(TableNewRow.Item("VariableValue"), "'") Then
    
    
    
    
    
    
    
     strCom = "INSERT INTO [Specialvariables] VALUES ('" & TableNewRow.Item("VariableName") & "', '" & Replace(TableNewRow.Item("VariableValue"), "'", "´") & "')"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     strCom = "INSERT INTO [Specialvariables] VALUES ('" & TableNewRow.Item("VariableName") & "', '" & TableNewRow.Item("VariableValue") & "')"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     'CREAMOS EL OBJETO COMANDO
    
    
    
    
    
    
    
     Dim comando As New OleDb.OleDbCommand(strCom)
    
    
    
    
    
    
    
     comando.Connection = conConn
    
    
    
    
    
    
    
     If DatatableIsOpen = False Then
    
    
    
    
    
    
    
     conConn.Open()
    
    
    
    
    
    
    
     DatatableIsOpen = True
    
    
    
    
    
    
    
     End If
    
    
    
    'Finally I record that variable and fixes loop to keep connection open or close it (saving time)
    
    
    
     comando.ExecuteNonQuery()
    
    
    
    
    
    
    
     Next
    
    
    
    
    
    
    
     conConn.Close()
    
    
    
    
    
    
    
     DatatableIsOpen = False
    
    
    
    
    
    
    
     End Using
    
    
    
    
    
    
    
     Dim ctl As Control
    
    
    
    'Main form's controls
    
    
    
     Dim BackendTable As New DataTable("Backend")
    
    
    
    
    
    
    
     Dim VariableNameBackend As DataColumn = New DataColumn("VariableName")
    
    
    
    
    
    
    
     VariableNameBackend.DataType = System.Type.GetType("System.String")
    
    
    
    
    
    
    
     BackendTable.Columns.Add(VariableNameBackend)
    
    
    
    
    
    
    
     Dim VariableValueBackend As DataColumn = New DataColumn("VariableValue")
    
    
    
    
    
    
    
     VariableValueBackend.DataType = System.Type.GetType("System.String")
    
    
    
    
    
    
    
     BackendTable.Columns.Add(VariableValueBackend)
    
    
    
    
    
    
    
     VariableNameBackend = New DataColumn("VariableName")
    
    
    
    
    
    
    
     VariableValueBackend = New DataColumn("VariableName")
    
    
    
    
    
    
    
     For Each ctl In backend.Controls
    
    
    
    'Now iterates over all controls, and get its properties and values. Fnally I store them as usual
    
    
    
     If TypeOf ctl Is TextBox Then
    
    
    
    
    
    
    
     VarName = ctl.Name
    
    
    
    
    
    
    
     VarValue = ctl.Text
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = True
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Recopilando cálculo térmico...(" & ProgressBarValue & " registros totales guardados)"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Gathering thermal calculus...(" & ProgressBarValue & " total saved entries)"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     ElseIf TypeOf ctl Is CheckBox Then
    
    
    
    
    
    
    
     VarName = ctl.Name
    
    
    
    
    
    
    
     VarValue = CType(ctl, CheckBox).CheckState
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = True
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Recopilando cálculo térmico...(" & ProgressBarValue & " registros totales guardados)"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Gathering thermal calculus...(" & ProgressBarValue & " total saved entries)"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     ElseIf TypeOf ctl Is ComboBox Then
    
    
    
    
    
    
    
     VarName = ctl.Name
    
    
    
    
    
    
    
     VarValue = CType(ctl, ComboBox).Text
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = True
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Recopilando cálculo térmico...(" & ProgressBarValue & " registros totales guardados)"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Gathering thermal calculus...(" & ProgressBarValue & " total saved entries)"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     ElseIf TypeOf ctl Is DateTimePicker Then
    
    
    
    
    
    
    
     VarName = ctl.Name
    
    
    
    
    
    
    
     VarValue = ctl.Text
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = True
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Recopilando cálculo térmico...(" & ProgressBarValue & " registros totales guardados)"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Gathering thermal calculus...(" & ProgressBarValue & " total saved entries)"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     ElseIf TypeOf ctl Is GroupBox Then
    
    
    
    
    
    
    
     Dim ctlgrp As Control
    
    
    
    
    
    
    
     For Each ctlgrp In ctl.Controls
    
    
    
    
    
    
    
     If TypeOf ctlgrp Is TextBox Then
    
    
    
    
    
    
    
     VarName = ctlgrp.Name
    
    
    
    
    
    
    
     VarValue = ctlgrp.Text
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = True
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
      SavingSplash.SavingDatalb.Text = "Recopilando cálculo térmico...(" & ProgressBarValue & " registros totales guardados)"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
      SavingSplash.SavingDatalb.Text = "Gathering thermal calculus...(" & ProgressBarValue & " total saved entries)"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     ElseIf TypeOf ctlgrp Is CheckBox Then
    
    
    
    
    
    
    
     VarName = ctlgrp.Name
    
    
    
    
    
    
    
     VarValue = CType(ctlgrp, CheckBox).CheckState
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = True
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
      SavingSplash.SavingDatalb.Text = "Recopilando cálculo térmico...(" & ProgressBarValue & " registros totales guardados)"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
      SavingSplash.SavingDatalb.Text = "Gathering thermal calculus...(" & ProgressBarValue & " total saved entries)"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     ElseIf TypeOf ctlgrp Is ComboBox Then
    
    
    
    
    
    
    
     VarName = ctlgrp.Name
    
    
    
    
    
    
    
     VarValue = CType(ctlgrp, ComboBox).Text
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = True
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
      SavingSplash.SavingDatalb.Text = "Recopilando cálculo térmico...(" & ProgressBarValue & " registros totales guardados)"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
      SavingSplash.SavingDatalb.Text = "Gathering thermal calculus...(" & ProgressBarValue & " total saved entries)"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     ElseIf TypeOf ctl Is DateTimePicker Then
    
    
    
    
    
    
    
     VarName = ctl.Name
    
    
    
    
    
    
    
     VarValue = ctl.Text
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = True
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
      SavingSplash.SavingDatalb.Text = "Recopilando cálculo térmico...(" & ProgressBarValue & " registros totales guardados)"
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
      SavingSplash.SavingDatalb.Text = "Gathering thermal calculus...(" & ProgressBarValue & " total saved entries)"
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = False
    
    
    
    
    
    
    
     Continue For
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     If VarIsReadyToBeSaved = True Then
    
    
    
    
    
    
    
     TableNewRow = BackendTable.NewRow
    
    
    
    
    
    
    
     TableNewRow.Item("VariableName") = "" & VarName & ""
    
    
    
    
    
    
    
     TableNewRow.Item("VariableValue") = "" & VarValue & ""
    
    
    
    
    
    
    
     BackendTable.Rows.Add(TableNewRow)
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = False
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Next
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     VarIsReadyToBeSaved = False
    
    
    
    
    
    
    
     Continue For
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     If VarIsReadyToBeSaved = True Then
    
    
    
    
    
    
    
     TableNewRow = BackendTable.NewRow
    
    
    
    
    
    
    
     TableNewRow.Item("VariableName") = "" & VarName & ""
    
    
    
    
    
    
    
     TableNewRow.Item("VariableValue") = "" & VarValue & ""
    
    
    
    
    
    
    
     BackendTable.Rows.Add(TableNewRow)
    
    
    
    
    
    
    
     ProgressBarValue = ProgressBarValue + 1
    
    
    
    
    
    
    
     SavingSplash.SavingDataPb.Value = ProgressBarValue
    
    
    
    
    
    
    
     Application.DoEvents()
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Next
    
    
    
    
    
    
    
     If SelectedLanguage = "Español" Then
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Guardando cálculo térmico..."
    
    
    
    
    
    
    
     Else
    
    
    
    
    
    
    
     SavingSplash.SavingDatalb.Text = "Saving thermal calculus..."
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     Using conConn As New OleDb.OleDbConnection(strConn)
    
    
    
    
    
    
    
     For Each TableNewRow In BackendTable.Rows
    
    
    
    
    
    
    
     'CREAMOS EL STRING DE CONEXION
    
    
    
    
    
    
    
     strCom = "INSERT INTO [Backend] VALUES ('" & TableNewRow.Item("VariableName") & "', '" & TableNewRow.Item("VariableValue") & "')"
    
    
    
    
    
    
    
     'CREAMOS EL OBJETO COMANDO
    
    
    
    
    
    
    
     Dim comando As New OleDb.OleDbCommand(strCom)
    
    
    
    
    
    
    
     comando.Connection = conConn
    
    
    
    
    
    
    
     If DatatableIsOpen = False Then
    
    
    
    
    
    
    
     conConn.Open()
    
    
    
    
    
    
    
     DatatableIsOpen = True
    
    
    
    
    
    
    
     End If
    
    
    
    
    
    
    
     comando.ExecuteNonQuery()
    
    
    
    
    
    
    
     Next
    
    
    
    
    
    
    
     DatatableIsOpen = False
    
    
    
    
    
    
    
     conConn.Close()
    
    
    
    
    
    
    
     End Using
    
    
    
    
    
    
    
    '... doing a lot more of stuff, similar to the aboves.
    
    
    
    objSaveFileDialog.Dispose()
    
    
    
    End sub
    
    
    
    
    
    
    
    
    
    
    
    

    The estructure is always the same, so, maybe in this piece of code someone could see some mistake. Thanks in advance.

    Morg

     



    • Edited by Morglum007 Wednesday, July 27, 2011 6:59 AM Solved
    Tuesday, July 26, 2011 9:43 AM

Answers

  • Solved. After strugging all the day with that, came around with a non fashioned way that works.

    Tried many things, disposing by hand datasets and datatables (even not being idisposable: automatically closed after executed), rearranging random names for variables to be involved and also trying to duplicate savefiledialog instance (uh oh... quite impossible? not really, but who will like to do it?).

    After all this testing, tried a very simple thing, created my own controlled form with same saving piece of code, and voilá, no problems, no matter how many times I wish to save something, no matter the name, no matter the path, everything works as it should.

    Obviosly, savefiledialog have something to do with my problems, so erradicated from my life. As I dont really want to deal with Olly debugger and Windows APIs, this is a faster and simpler solution. I heard before that most times Windows API are obscure and quite "dark" when tracing, now I can asure it by myself.


    Anyway, thread solved, so I mark it as it and archive.


    Thank you everybody for trying to help.


    Have a nice day.

    • Marked as answer by Paul Zhou Thursday, July 28, 2011 5:08 AM
    Wednesday, July 27, 2011 6:58 AM

All replies

  • Solved. After strugging all the day with that, came around with a non fashioned way that works.

    Tried many things, disposing by hand datasets and datatables (even not being idisposable: automatically closed after executed), rearranging random names for variables to be involved and also trying to duplicate savefiledialog instance (uh oh... quite impossible? not really, but who will like to do it?).

    After all this testing, tried a very simple thing, created my own controlled form with same saving piece of code, and voilá, no problems, no matter how many times I wish to save something, no matter the name, no matter the path, everything works as it should.

    Obviosly, savefiledialog have something to do with my problems, so erradicated from my life. As I dont really want to deal with Olly debugger and Windows APIs, this is a faster and simpler solution. I heard before that most times Windows API are obscure and quite "dark" when tracing, now I can asure it by myself.


    Anyway, thread solved, so I mark it as it and archive.


    Thank you everybody for trying to help.


    Have a nice day.

    • Marked as answer by Paul Zhou Thursday, July 28, 2011 5:08 AM
    Wednesday, July 27, 2011 6:58 AM
  •  

    I'm glad to hear that you got it working.

    Thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, July 28, 2011 5:08 AM