Attempted to read or write protected memory RRS feed

  • Question

  • Hi there

    I wrote an app that gets two excel sheets and puts them in two datattables for processing . since there a number of posible sheets the user has to define which kind of sheets he is feeding. this is achieved by selecting from two diffferent combos which are connected to two access tables.

    this is the code that connects to the combo (the other one is similar):

      oddaRekhev = New OleDb.OleDbDataAdapter("select company,CompID from Companies order by company", conex)
      CBRekhev = New OleDb.OleDbCommandBuilder(oddaRekhev)
      cmb_company.DataSource = DTRekhev
      cmb_company.DisplayMember = "company"
      cmb_company.ValueMember = "CompID"
      cmb_company.SelectedValue = "14"
      cmb_company.Text = "Choose company"

    after the user selects the combos he  selects the excel sheets:

    'Connects to Client Database
      Dim MyCommand As OleDb.OleDbDataAdapter
      Dim MyConnection As OleDb.OleDbConnection
       MyConnection = New OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & "data source=" & path & "; Extended Properties=Excel 8.0; ")
       ' Select the data from Sheet1 of the workbook.
       MyCommand = New OleDb.OleDbDataAdapter("select * from [" & sheet & "$] ", MyConnection)
      Catch ex As Exception
       MsgBox(ex.Message & " Source: " & ex.Source, MsgBoxStyle.Exclamation, ex.InnerException)
      End Try


    here comes the problem:

    on some computers I installed the app everything runs fine. but on other computers on the last code is where I get the exception

    and if thats not weird enough listen to this:

    if I skip the combo selection part (say by typing the possibilities intsead of choosing them) then the app runs fine

    I've been struggling with this issue for weeks now

    please may someone have the great wisdom of knowing the solution



    Monday, July 4, 2011 7:08 AM


  • Extended Properties part of the connection string should be enclosed into additional double quotes. That could be the reason. If you look at the final connection string it should be something like

    "provider=Microsoft.Jet.OLEDB.4.0;data source=C:\MyFolder;"Extended Properties=Excel 8.0;""


    Val Mazur (MVP)


    • Marked as answer by Jackie-Sun Wednesday, August 3, 2011 8:19 AM
    Wednesday, July 6, 2011 10:39 AM

All replies