Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Attempted to read or write protected memory" error

Status
Not open for further replies.

TheVampire

Programmer
May 1, 2002
828
US
I'm getting an "Attempted to read or write protected memory" error when filling a DataTable. I've done a lot of checking into this error and tried many different things but cannot get it solved.

This error does not occur on my development system. It only occurs on the users system. Note that the user is running the program on MS Virtual Server 2005, so this may be the reason I do not see the problem. It may even be the reason that the error is occuring. I asked the user to set their page file size to "fixed" in VS but that had no effect.

In my code I have a class that is created to communicate through a COM port to an access control system and store data received from this system. The PC has several COM ports on it, all connected to different "sites" where access control systems are installed. As I loop through the sites I create the class, initialize it with the COM port #, the path for the database files for that site, and then connect. Once I am done with a site I destroy the class and then go on to the next site.

In the class I have a DataTable is being filled from an OleDbDataAdapter, using a SELECT command.

The first site I connect to and run through works fine with no errors. I can see in my progam log that the routine that fills the DataTable is executed many times without a problem, but the second site I connect to, the protected memory error occurs the first time I try to fill the DataTable with the results from the SELECT command.

It does not matter what order the sites are done in, the error always occurs on the second one.

The class uses IDisposable and is being disposed of correctly. I'm even forcing garbage collection with System.GC.Collect() before recreating the class.


Does anyone have any suggestions as to what else I might try?
 

Are you disposing of all the objects in the class when you dispose of the class? Disposing of the class should take care of this, but it might help to explicitly dispose of any objects.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks for the reply. I am disposing of each object that is disposable ( my OleDbConnection and my IO.Ports.SerialPort ) and also setting the references to nothing for everything else.
 
Well, I've done some searching and unfortunately it seems there are many possible causes for this error.

Check out this link and see if anything in there helps you:



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
jebenson,

Thanks for trying. I'd seen that page before in my searches on this particular error, and tried some of the things listed. Most of the items were not applicable to my situation, or were options that were in VS2005 but not in VS2008 Express (such as compile for a certain target platform).

I'm pretty convinced that it's the virtual server my user is running that is messing things up.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top