Andrea
Andrea

Reputation: 894

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

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?

Upvotes: 11

Views: 11038

Answers (4)

Brad Bruce
Brad Bruce

Reputation: 7827

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.

Upvotes: 0

moke
moke

Reputation: 2621

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);

Upvotes: 2

Mike Mayer
Mike Mayer

Reputation: 169

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.

Upvotes: 5

tsells
tsells

Reputation: 2771

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.

Upvotes: 7

Related Questions