recently in my project when I call ShowDialog
method of OpenFileDialog
I get this error:
\"Attempted to read or write protected memory. Thi
I had this problem too.
I was using OpenFileDialog to select an Excel file, then read the data with .net Oledb and write data to Access database.
The first time: OK
The second time, after select file, appeared this message: Attempted to read or write protected memory
My solution:
A form "A" with an OpenFileDialog and a button to display and select files and: openFileDialog1.ReadOnlyChecked = true; openFileDialog1.ShowReadOnly = true;
A form "B" With a get/set to set the filename to read A method to read excel file and write to Access db.
From "A", send filename to read to "B" form Load "B" form, execute the main process, view results and close form On return "A", I could select another file and repeat the process without errors
No more "Attempted to read or write protected memory" error
I don't know if it's the best solution but the application runs well.
Greetings
This is solved my problem. In Connection string add the OLE DB Services=-1
then its working.
Like this:
Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\DbTest\Test.accdb; OLE DB Services=-1
Or as shown in this link
OpenFileDialog loads a large amount of unmanaged code into your process. All of the shell extensions that you have installed on your machine. One of them isn't very happy about your process environment, or messes with your process enough to make it crash and burn.
You'll need to find the shell extension that causes this. Start with Project + Properties, Debug tab, tick the "Enable unmanaged code debugging" option. You'll now see the list of DLLs that get loaded in the Output window. Odds are reasonable that the last one you see before you get the exception is the trouble-maker. Although you'll still have to reverse-engineer the DLL name to the shell extension name.
The other approach is slash and burn. Use SysInternals' AutoRuns utility. Click the Explorer tab and disable anything that wasn't made by Microsoft. Ask more questions about this at superuser.com