Thursday, August 14, 2008

Error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Error: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

This error can come because of multiple reasons. I faced this issue while I have Oracle 10g and Oracle Express install.
If you have Oracle 10g and visual studio 2.0 in your machine and you over that you install
Oracle express edition.
Now if you try to connect Oracle 10g or Oracle XE to execute any SQL statement or stored procedure from .NET using "Oracle.DataAccess.dll" then you will get following error:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Exception Type: AccessViolationException was unhandled

Why:
Actually when you have oracle 10g installed in your machine and then you install Oracle XE, Then Oracle XE adds its path first in the system environment variable.
Basically Oracle XE Bin folder and Oracle 10g Bin folder have same "Oracle.DataAccess.dll" DLL. When you run .NET application which is using this "Oracle.DataAccess.dll" DLL, then will give first preference to Oracle XE DLL and somehow .NET will throw an error. So Problem is in Oracle XE "Oracle.DataAccess.dll" DLL.

Solution -1
The solution is; Change path order in the system environment variable; move Oracle XE path after Oracle 10g Path.
How
Go to 'My computer' --> right click and go to 'Property' --> go to 'Advance Tab' --> Click 'Environment Variable' button --> in the 'System variable' section select 'Path' and --> click 'Edit' button --> now change the variable value
Before: C:\oraclexe\app\oracle\product\10.2.0\server\bin; c:\oracle\10gR2Client\bin;
After: c:\oracle\10gR2Client\bin; C:\oraclexe\app\oracle\product\10.2.0\server\bin;
Maroon: Oracle 10g Path
Blue: Oracle XE path
Click "OK" then again "OK" and restart your system. This error should not be there.
Solution-2
Always install Oracle XE before Oracle 10g other wise Oracle XE will overwrite "Oracle.DataAccess.dll" DLL from Oracle 10 g DLL.