Attempted to read or write protected memory in Oracle 11g with ODP.NET
Asked Answered
S

4

11

I am developing an application that is supposed to run for long periods and make extensive usage of an Oracle (11g) database via ODP.NET.

It happens, though, that once in a while (every 2 or 3 days) a System.AccessViolationException is thrown by ODP.NET and then the application needs to be restarted. Here is my stack trace:

Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. 
---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Oracle.DataAccess.Client.OpsSql.Prepare2(IntPtr opsConCtx, IntPtr& opsErrCtx, IntPtr& opsSqlCtx, IntPtr& opsDacCtx, OpoSqlValCtx*& pOpoSqlValCtx, string pCommandText, IntPtr& pUTF8CommandText, OpoMetValCtx*& pOpoMetValCtx, Int32 prmCnt)
at Oracle.DataAccess.Client.OracleCommand.ExecuteNonquery()

The rest of the stack trace is different from time to time and refers to internal calls from my application.

Now, I've made a fair amount of research before asking here, but I have found nothing conclusive. A number of other people are apparently experiencing the very same problem, although the root causes seem to vary a lot. I really hope somebody has a solution for this one :-)

On an unrelated note, it appears that this exception is capable of ignoring my catch {} blocks and result in an application crash every time it occurs. Is that because it is related to memory corruption issues?

Regards, Andrea

edit: further investigation led me to believe that it could be worth starting the "Distributed Transactions Coordinator" service and see if the exception stops being thrown. What do you think?

Sloane answered 1/7, 2011 at 15:50 Comment(1)
FYI the reason it ignores your try / catch blocks is because it takes down the whole dot.net stack when the unmanaged portion of the code crashes.Freeswimming
F
7

This is a bug. The 11.1 and 11.2 providers had this issue. The only way to get around this is to install the 11.2.0.2 client and then apply patch 6.

Freeswimming answered 23/8, 2011 at 3:57 Comment(1)
Could you provide some details on where to find "patch 6"?Equities
F
5

While constructing my OracleCommand object and adding parameters...

I found that changing from:

select.Parameters.Add("Result", OracleDbType.RefCursor);

To:

select.Parameters.Add("Result", OracleDbType.RefCursor, ParameterDirection.Output);

Eliminated this problem for me on the 11.2.0.2 client.

Forejudge answered 16/11, 2011 at 23:19 Comment(0)
T
2

We experienced the same AccessViolationException because an RefCursor was declared as an input parameter instead of Output.

command.Parameters.Add("O_RECS", OracleDbType.RefCursor, null, ParameterDirection.Input);

This is a harsh message for such a simple mistake. Changing the parameter direction fixed the error.

command.Parameters.Add("O_RECS", OracleDbType.RefCursor, null, ParameterDirection.Output);
Twoup answered 13/4, 2016 at 15:17 Comment(0)
G
0

For anyone else finding this issue. If you do not have an appropriate value for BatchSize, you could run out of memory. This yields the same error.

Governance answered 26/7, 2019 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.