Accessviolation, Attempt to r/w protected memory, when using Oracle with ADO.Net RRS feed

  • Question

  • I have a relatively simple C# .Net 2.0 application that I've authored which has a problem in the area of ADO.Net.  The first time after booting up the computer, when the code tries to perform an Update of any kind against the Oracle database via ADO.Net, it throws this exception.  After that, it runs flawlessly, but after every re-boot of the computer on first time through it has this error. 


    Note: this error does not happen when I use SQLServer classes; the same code rune fine (same except using SqlCommand and SqlConnection that is of course). 



    If I go to Component Services --- My Computer --- and stop and then restart MSDTC, doing this BEFORE I run the app, it seems like it avoids this error happening.  SO it seems like it is some wierd thing where MSDTC is not ready-to-go until after the OracleClient tries to join the transaction the first time, then on successive times it must be ready-to-go so no error happens.  ???  Kind of a guess.  But I can't ask my users to go reset MSDTC after they boot, so I really need a code fix of some kind, or a code work-around, or at least to document that it is a Framework bug and not something I can work-around in my code. 


    Chronological Recap of the events:

    1. Machine running XP SP2 is booted, logged into

    2. User runs the application

    3. User runs any function that runs SQL SELECT stored procs, everything is fine

    4. User runs function that attempts to UPDATE or INSERT, and the stack-dump occurs

    5. User restarts application, now all SQL works fine, SELECT, INSERT, UPDATE, DELETE  (until the next reboot)


    Stacktrace Analysis:

    Since the stack trace points to Connection.Open() as the error, obviously at the time the connection is being opened it doesn't know if the code is going to execute a SELECT or an UPDATE, so it must be that the UPDATE actually succeeds, but after the UPDATE when my code goes on to re-read the row, at that time it executes getCnUPD( ) again which again opens a Connection and that's probably when the error is happening, which makes sense per the stacktrace indicating it is during OraMTSJoinTxn.  (On successive executions this works flawlessly, opening a second Connection is not unusual and works on thousands of rows after the first reboot/failure sequence.)


    Comments about the Transactions:

    As you can see in the code, I am not using the Connection.Transaction (it is set null), rather, my code is using either no transaction, or it sets Transaction.Current = new System.Transaction.CommittableTransaction(TransactionOptions).  Both the Update and the SELECT code run in the same thread and hence the SELECT can see the data written by the UPDATE.  This all works fine after the first-time it is run.  The code dies whether I use absolutely no transaction or if I put a transaction into scope as just described. 


    This all works perfectly with SqlConnection classes, it only dies when using ORACLE Connection classes.


    Here's a sample section of the code that's running when the error happens, and following that is the stacktrace.





    private Class OracleServiceBase {

      private OracleConnection   getCnUPD(Boolean useRefDB) {

        OracleCommand cmd = new OracleCommand();

        OracleConnection cnUPD = new OracleConnection();

        cnUPD.ConnectionString = "Data Source=xxx; User ID=xxx; Pasword=xxx");

        cnUPD.Open();  //the stack trace points to here, but all this code works fine if it is executing a SELECT,

                                //so maybe it's the attempt to open a Connection AFTER the first UPDATE or INSERT stmt

        OracleCommand cmd = new OracleCommand();

        cmd.Connection = cnUPD;

        cmd.Transaction = null;

        cmd.CommandType = CommandType.StoredProcedure;

        cmd.CommandText = "MyStoredProcName";

        int i = cmd.ExecuteNonQuery(); 


    MarkerNotebook received an error: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
       at System.Data.Common.UnsafeNativeMethods.OraMTSJoinTxn(OciEnlistContext pCtxt, IDtcTransaction pTrans)
       at System.Data.OracleClient.TracedNativeMethods.OraMTSJoinTxn(OciEnlistContext pCtxt, IDtcTransaction pTrans)
       at System.Data.OracleClient.OracleInternalConnection.Enlist(String userName, String password, String serverName, Transaction transaction, Boolean manualEnlistment)
       at System.Data.OracleClient.OracleInternalConnection.Activate(Transaction transaction)
       at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)
       at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
       at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
       at System.Data.OracleClient.OracleConnection.Open()
       at SNPCropServices.OracleServiceBase.getCnUPD(Boolean useRefDB) in

    Monday, October 29, 2007 3:41 PM


All replies

  • It is a known issue with hot fix and changing the driver solutions.  Try the link below for details.  Hope this helps.




    Monday, October 29, 2007 4:07 PM

    The symptoms, asmentioned in the previous post, are code security problems, it is code that flat-out will not run.  My code runs flawlessly except for the very first time it runs after a reboot. 


    I am sure that the error "AccessViolation: Attempted to read or write protected memory" symptom as reported in my problem happens for many different reasons; the reasons the reasons cited in the previous post do not apply to my problem scenario. 


    Just to be sure... I got the hotfix, applied it, same error still occurs.





    Monday, October 29, 2007 6:12 PM
  • Try the thread below it references another thread in this forum see if it helps if not post at the CLR forum you could get help from Microsoft employees.


    Tuesday, October 30, 2007 9:09 PM
  • Caddre,

    That was a nice suggestion, but it does not apply to my scenario. 



    Wednesday, October 31, 2007 3:38 PM

    I don't have an answer to your situation, but recently I came across the same AccessViolationException in my OracleConnection.Open() call.  After spending days looking and trying various things, I uninstalled my 10g client and installed 11g client.  Afterwards, the error returned from Oracle was more meaning -- instead of AccessViolationException, I got ORA-12640, which pointed me in the right direction of the root cause.  Turned out that my sqlnet.ora was incorrect.  I fixed my sqlnet.ora, uninstall 11g client, reinstall 10g client, and no more exceptions !


    Maybe if you try 11g client, you will get something more meaning than AccessViolationException that will point you in the right direction towards a fix.


    Sunday, November 11, 2007 7:39 AM
  • THIS WAS ANSWERED, IN THE COMMON LANGUAGE RUNTIME FORUM.  Search for posting with nearly the same key heading as this one.  THis link might take you there.





    Wednesday, November 14, 2007 5:21 AM