This discussion is archived
1 2 Previous Next 17 Replies Latest reply: Jun 15, 2010 11:12 AM by 411565 RSS

Attempted to read or write protected memory

501228 Newbie
Currently Being Moderated
I'm trying to read data using a command object within .net 2.0. most of our developer machines are working fine. However one developer machine, and the dev server are coming up with the following exception when i try and connect to oracle and do anything.



at Oracle.DataAccess.Client.OpsSql.ExecuteReader(IntPtr opsConCtx, IntPtr& opsErrCtx, IntPtr& opsSqlCtx, IntPtr opsSubscrCtx, Int32& isSubscrRegistered, OpoSqlValCtx*& pOpoSqlValCtx, OpoSqlRefCtx& pOpoSqlRefCtx, IntPtr[] pOpoPrmValCtx, OpoPrmRefCtx[] pOpoPrmRefCtx, OpoMetValCtx*& pOpoMetValCtx, Int32 NoOfParams)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader()
at Oracle.DataAccess.Client.OracleCommand.ExecuteScalar()
at ConsoleAppTest.Class1.authenticateLogin(String username, String password) in C:\Inetpub\wwwroot\ConsoleAppTest\Class1.cs:line 210

Oracle.DataAccess

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

System.AccessViolationException

Int32 ExecuteReader(IntPtr, IntPtr ByRef, IntPtr ByRef, IntPtr, Int32 ByRef, Oracle.DataAccess.Client.OpoSqlValCtx* ByRef, Oracle.DataAccess.Client.OpoSqlRefCtx ByRef, IntPtr[], Oracle.DataAccess.Client.OpoPrmRefCtx[], Oracle.DataAccess.Client.OpoMetValCtx* ByRef, Int32)

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Oracle.DataAccess.Client.OpsSql.ExecuteReader(IntPtr opsConCtx, IntPtr& opsErrCtx, IntPtr& opsSqlCtx, IntPtr opsSubscrCtx, Int32& isSubscrRegistered, OpoSqlValCtx*& pOpoSqlValCtx, OpoSqlRefCtx& pOpoSqlRefCtx, IntPtr[] pOpoPrmValCtx, OpoPrmRefCtx[] pOpoPrmRefCtx, OpoMetValCtx*& pOpoMetValCtx, Int32 NoOfParams)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader()
at Oracle.DataAccess.Client.OracleCommand.ExecuteScalar()
at ConsoleAppTest.Class1.authenticateLogin(String username, String password) in C:\Inetpub\wwwroot\ConsoleAppTest\Class1.cs:line 210

I've read alot of people with the problem, but no solutions seem to be out there.

Has anyone had this problem? and if so why? I cant find anyway arround it. The code we are running is dirt simple. "select userID from HCD02.tblUserLoginCredentials where username = :username and password = :password" and it works on .net 1.1 but not on .net 2.0? however it does work on .net 2.0 on most of our developer machines.
  • 1. Re: Attempted to read or write protected memory
    gdarling - oracle Expert
    Currently Being Moderated
    Hi Brian,

    I've never heard of anyone having that problem myself anyway.
    What I'd suggest you do to start with is get Process Explorer from http://sysinternals.com which will let you see what dlls/versions are loaded by the app, and confirm that the same dll versions are loaded on both the "good" and "bad" machines.
    You may also want to check to see if it repro's with a simple console odp app just to simplify the environment.

    Cheers
    Greg
  • 2. Re: Attempted to read or write protected memory
    524819 Newbie
    Currently Being Moderated
    Have the same problem
  • 3. Re: Attempted to read or write protected memory
    kakiyama Newbie
    Currently Being Moderated
    Hi,

    Do you have a simple test case that can reproduce this problem?

    Thank you.
  • 4. Re: Attempted to read or write protected memory
    530103 Newbie
    Currently Being Moderated
    I am getting the very same exception (System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt) when using the Command Object.

    Very interested in knowing if there is a pubished MS fix.
  • 5. Re: Attempted to read or write protected memory
    560468 Newbie
    Currently Being Moderated
    Any solution to this problem?
  • 6. Re: Attempted to read or write protected memory
    475093 Newbie
    Currently Being Moderated
    I had exactly the same problem when publishing a web application on one of our servers. In our case the problem was quite obvious. The version of Oracle.AccessAccess.dll (10.2.0.1) which was used by the application did not correspond to the version of the Oracle client framework which was installed on the server (10.1.xxx).

    By uninstall the Oracle Client 10.1.x and install 10.2.0.1 the problem was solved.
  • 7. Re: Attempted to read or write protected memory
    319528 Newbie
    Currently Being Moderated
    We get this error often in batch. It is always when selecting from a table with a clob column were the column is referenced in the select list. If we re-run the program that got the error with no changes, it will always run successful.

    Actually, I have seen the error repeat once in a while. But, by re-running the program, the problem goes away. Somehow, I think that the Oracle provider is conflicting with .net's garbage collection.

    Best regards,

    Metro.
  • 8. Re: Attempted to read or write protected memory
    572474 Newbie
    Currently Being Moderated
    Can some one post the code that having problem to the forum so other who has interest can actually try it out?

    Ming Man
  • 9. Re: Attempted to read or write protected memory
    416749 Newbie
    Currently Being Moderated
    I have the same problem on a different machine. It works on mine and I get the memory error on the other machine, same code. I am guessing there might be a conflict with the multiple versions of Oracle installed on that machine.
  • 10. Re: Attempted to read or write protected memory
    416749 Newbie
    Currently Being Moderated
    Just for the info. I fixed this by removing all the other versions.
  • 11. Re: Attempted to read or write protected memory
    582855 Newbie
    Currently Being Moderated
    Just for the info. I fixed this by removing all the
    other versions.
    Hi, what do you mean by 'other versions'. Please can you be more explicit.
  • 12. Re: Attempted to read or write protected memory
    608713 Newbie
    Currently Being Moderated
    Hi Guys,

    I do have the same problem.
    Environment:

    .NET 2.0
    Client: ORACLE DATA PROVIDER FOR .NET 11.1.0.6.10 BETA
    Database: Oracle 10g

    Here where the exception is thrown:

    STEP1:
    I've created a User Defined object in .NET class as below:

    using System;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;

    namespace Thomson.PdrIndex.Common.BusinessEntities.ProcObjects
    {
    public class Employee : IOracleCustomType, INullable
    {
    private int _id;
    private string _name;
    private bool _isNull;

    [OracleObjectMappingAttribute(0)]
    public int Id
    {
    get
    {
    return _id;
    }
    set
    {
    _id = value;
    }
    }

    [OracleObjectMappingAttribute(1)]
    public string Name
    {
    get
    {
    return _name;
    }
    set
    {
    _name = value;
    }
    }

    public virtual bool IsNull
    {
    get
    {
    return _isNull;
    }
    }

    public static Employee Null
    {
    get
    {
    Employee employee = new Employee();
    employee._isNull = true;
    return employee;
    }
    }

    public virtual void ToCustomObject(OracleConnection con, IntPtr pUdt)
    {
    if (!OracleUdt.IsDBNull(con, pUdt, 0))
    {
    _id = (int)OracleUdt.GetValue(con, pUdt, 0);   
    }

    if (!OracleUdt.IsDBNull(con, pUdt, 1))
    {
    _name = (string)OracleUdt.GetValue(con, pUdt, 1);
    }
    }

    public virtual void FromCustomObject(OracleConnection con, IntPtr pUdt)
    {
    OracleUdt.SetValue(con, pUdt, 0, _id);
    OracleUdt.SetValue(con, pUdt, 1, _name);
    }
    }

    [OracleCustomTypeMappingAttribute("FIELD_TYPE_OT")]
    public class EmployeeFactory : IOracleCustomTypeFactory
    {
    public IOracleCustomType CreateObject()
    {
    return new Employee();
    }
    }
    }

    NOTE:
    Database has

    1. the following obect type:
    FIELD_TYPE_OT
    with field1 as integer, field2 as varchar2(100)

    2. Stored Procedure:
    PROCEDURE fetch_object_pr (
    p_obj IN field_type_ot

    )
    AS
    BEGIN

    INSERT INTO yogi_collection
    (id,
    name
    )
    VALUES (p_obj.o_field_id,
    p_obj.o_field_name
    );

    DBMS_OUTPUT.put_line ('Successful');

    END fetch_object_pr;


    STEP 2:
    Employee emp = new Employee();
    emp.Id = 26;
    emp.Name = "Name26";

    and created an OracleCommand object and the constructor parameter.

    STEP3:
    when I debug my method to pass the UDT object to SP.
    I get the 'Attempted to read or write protected memory' at this line:

    Database.ExecuteNonQuery(base.Command);
    (Database object is created and this works for executing other SPs)

    Actually, 'CreateObject()' method in 'EmployeeFactory' class is invoked when this 'ExecuteNonQuery()' is called and the exception is thrown just after the 'CreateObject()' method execution.

    Exactly here:

    public IOracleCustomType CreateObject()
    {
    return new Employee();
    } <-- after executing this line.

    Please help me on this.

    Thanks in Advance.

    Regards,
    N. Yogendran
  • 13. Re: Attempted to read or write protected memory
    502182 Explorer
    Currently Being Moderated
    Do you still notice this problem in recent ODP.NET production release (11.1.0.6.20)?
  • 14. Re: Attempted to read or write protected memory
    683468 Newbie
    Currently Being Moderated
    Steps to resolve this issue in xp.(not sure it works for all cases)

    1) Open Control Panel
    2)Click on Performance and Maintenance
    3)Open Administartive Tools
    4)Click on Component Services Icon, It opens a Window(Component services)

    5)In leftside Window you can see a tree view headed by 'Console Root',Under that 'component services' node will be there; on expanding that node you can view 'Computers' icon just click on it you can view 'MyComputer' icon on Right side window.

    6)Right click on MYcomputer icon at RightSide Window

    7)Go to Properties -->click on MSDTC TAB,in the bottom of this TAB you find a 'security Configuration' Button

    8) Check 'Network DTC Access','Allow Remote Clients','Allow Remote Administartion','Allow Inbound','Allow OutBound','Enable Transaction Internet Protocol Transactions','Enable XA Transactions' check boxes.

    9)select 'No Authentication Required' Radio button.

    10) Click Ok and restart the PC.
1 2 Previous Next