These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: NHibernate.Driver.OracleClientDriver friendly w/TransScope?
PostPosted: Thu Apr 09, 2009 7:24 am 
Beginner
Beginner

Joined: Mon Jan 05, 2009 7:08 am
Posts: 24
hello

Anybody knows if "NHibernate.Driver.OracleClientDriver" friendly with .NET TransactionScope/System.Data.OracleClient?

I can't get around a weird "System.AccessViolationException" on NHibernate ISession.Save.
"System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
The same piece of code works fine with M$SQL and MySQL. I tried switching over from "System.Data.OracleClient" to "Oracle.DataAccess.Client" (ODP.NET doc says it support TransactionScope) - however, the application simply disappear without even getting an AccessViolationException. In this case, last thing I see in log is:
Code:
2009-04-09 21:08:25,234 [10] DEBUG NHibernate.AdoNet.AbstractBatcher - Opened new IDbCommand, open IDbCommands: 1
2009-04-09 21:08:25,234 [10] DEBUG NHibernate.AdoNet.AbstractBatcher - Building an IDbCommand object for the SqlString: select SYSTEMUSER_SEQ.nextval from dual
2009-04-09 21:08:25,250 [10] DEBUG NHibernate.SQL - select SYSTEMUSER_SEQ.nextval from dual
2009-04-09 21:08:25,250 [10] DEBUG NHibernate.Connection.DriverConnectionProvider - Obtaining IDbConnection from Driver
2009-04-09 21:08:27,390 [10] DEBUG NHibernate.AdoNet.AbstractBatcher - Closed IDbCommand, open IDbCommands: 0
2009-04-09 21:08:27,390 [10] DEBUG NHibernate.AdoNet.ConnectionManager - aggressively releasing database connection


Amazingly, it was fine for ODP.NET if I simply comment out TransactionScope - i.e. It persisted successfully! (In ODP.NET documentation it says explicitly that "Oracle.DataAccess.Client' supports TransactionScope").


I checked the following, none resolved the problem:
(a) Make sure M$ DTC startup automatic
(b) C:\oraclexe\app\oracle\product\10.2.0\server\NETWORK\ADMIN\sqlnet.ora
Change from:
SQLNET.AUTHENTICATION_SERVICES = (NTS)
To:
SQLNET.AUTHENTICATION_SERVICES= (NONE)

(c) Set OracleConnection.Unicode to true, i.e. add the following to connection string
Unicode=true;

(d) Be careful with LONG, LONG RAW, OBJECT, XMLTYPE - try comment out first if any.
REF: http://www.devart.com/forums/viewtop...98df036d5ef2da

I can't find anything "funny" with my Person's table. And like I said, ODP.NET saved this successfully if I just commented out TransactionScope! So it should have nothing to do with it!
Code:
               CREATE TABLE PERSON (
                  Id numeric(19,0) NOT NULL,
                  FirstName nvarchar2 (50) NOT NULL,
                  MiddleName nvarchar2 (50) NULL,
                  LastName nvarchar2 (50) NOT NULL,
                  PrimaryEmail nvarchar2 (190) NULL,
                  PersonType int default 1 NOT NULL,
                  CreateDate date default sysdate NULL,   
                  CreatedBy numeric(19,0) default -1 NULL,
                  LastUpdate date NULL,
                  LastUpdateBy numeric(19,0) NULL,
                  
                  CONSTRAINT PK_PERSON PRIMARY KEY (Id),
                  CONSTRAINT UK_PERSON_PRIMARYEMAIL UNIQUE (PrimaryEmail)
               )


And my NHibernate mapping file (Googled a bit don't think it is problem with NHibernate, also this Save works fine with MySQL and M$SQL, only Oracle making trouble):
Code:
               <class name="Person" table="Person">
                  <id name="Id" column="Id" type="Int64" unsaved-value="0">
                     <generator class="sequence">
                         <param name="sequence">SYSTEMUSER_SEQ</param>
                     </generator>
                  </id>
                  <property name="PrimaryEmail" column="PrimaryEmail" type="String(255)"/>
                  
                  <property name="Type" column="PersonType" type="Int32"/>
                  
                  <component name="Name" class="xxxxx.Util.Name">
                     <property name="FirstName" column="FirstName" type="String(50)" />
                     <property name="MiddleName" column="MiddleName" type="String(50)" />
                     <property name="LastName" column="LastName" type="String(50)" />
                  </component>
                  <component name="BasicAudit" class="xxxxx.Util.Security.BasicAudit">
                     <property name="CreateDate" column="CreateDate" type="DateTime"/>
                     <property name="CreatedBy" column="CreatedBy" type="Int64"/>
                     <property name="LastUpdate" column="LastUpdate" type="DateTime"/>
                     <property name="LastUpdateBy" column="LastUpdateBy" type="Int64"/>
                  </component>
                  <joined-subclass name="xxxxx.Util.Security.SystemUser" table="SystemUser">
                     <key column="PersonId" />
                     <property name="Logon" column="Logon" type="String(50)" />
                     <property name="PasswdHash" column="PasswdHash" type="Int32"/>
                  </joined-subclass>
                  <!-- Person.Properties not mapped, done manually ADO.NET in PersonDAO -->
               </class>


And here's application code:
Code:
public virtual long Save(ref IGenericTO oPerson)
      {
         ...

         try
         {
            // Wrapped in transaction scope and if I comment out TransactionScope the application simply hangs on INSERT/Save on ISession.Save/INSERT below (this is with Oracle only. M$SQL and MySQL okay)
            using (oScope = new TransactionScope())
            {
               DBSession.Flush();
               // This is NHibernate ISession.Save - "System.AccessViolationException: exception here! (Works fine with M$SQL and MySQL).
                                       // Also tried switch from "System.Data.OracleClient" to "Oracle.DataAccess.Client" - in which case application simply exited with no exception caught!
               nGeneratedId = (long)DBSession.Save(oPerson); << ***** WATCH THIS DIED HERE *****
               DBSession.Flush();
               
               ... other database operation done in ADO.NET ...
               
               oScope.Complete();
            }
         }
         catch (Exception ex)
         {
            ....Util.ApplicationException.Throw("Save failed", null, oPerson.ToString(), ex);
         }

         return nGeneratedId;
      }


(e) M$ Hot fix - as suggested by http://forums.asp.net/p/675515/675515.aspx

I downloaded "303312_intl_i386_zip.exe " from following M$ URL.

Unfortunately on my XP box with:
* .NET 3.5 SP1
* Oracle 10g Express
* System.Data.OracleClient Runtime version v2.0.50727
I had the following error while trying to install the fix:
"The upgrade patch canno be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade path."

The fix does indicate that it is intended for .NET 2.0 however:
"Article ID: 923028 - Last Review: March 25, 2009 - Revision: 4.0 FIX: Error message when you run a .NET Framework 2.0 Remoting application: "Unhandled Exception: System.AccessViolationException"
Download fix:
https://connect.microsoft.com/Visual...;wa=wsignin1.0

Any suggestion? Help! Really need some help on this.

REF:
http://forums.oracle.com/forums/thre...p;amp;tstart=0
http://www.devart.com/forums/viewtop...98df036d5ef2da
http://forums.asp.net/p/675515/675515.aspx

Stack trace (apologies for long ...)
Code:
2009-04-09 07:31:24,609 [10] ERROR SimpleConsoleTest - xxxxx.Util.ApplicationException Exception context: xxxxx.Util.ApplicationExceptionContext, Subject: Save failed, Description: xxxxx.Util.Person, Id:-1, Name:xxxxx.Util.Name, FirstName:John, MiddleName:, LastName:Kennedy, PrimaryEmail:john.kennedy@gmail.com, Type:undefined, GenericObj:object type: xxxxx.Util.Generic.GenericObject, object name: , object classifier: Person, TypeName: xxxxx.Util.Person, DAOTypeName: xxxxx.Util.PersonDAO, Util, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, DAOCreateInstanceArg: , CreateDate: 4/9/2009 7:31:19 AM, Properties: , Parents count:0, Children:, DatabaseInitiated: False, BasicAudit:xxxxx.Util.Security.BasicAudit, CreateDate:4/9/2009 7:31:19 AM, CreatedBy:-1, LastUpdate:1/1/1753 12:00:00 AM, LastUpdateBy:-1, StackTrace:    at xxxxx.Util.ApplicationException.Throw(String strSubject, String strSummary, String strDescription, Exception oInnerException) in C:\dev\xxxxx\NET3.0\Util\ApplicationException.cs:line 176
            at xxxxx.Util.PersonDAO.Save(IGenericTO&amp;amp; oPerson) in C:\dev\xxxxx\NET3.0\Util\PersonDAO.cs:line 349
            at xxxxx.NUnitTest.TestDAOUtil.TestSaveAndSelectByKey(IGenericTO&amp;amp; o) in C:\dev\xxxxx\NET3.0\NUnitTest\TestDAOUtil.cs:line 349
            at xxxxx.NUnitTest.TestDAOUtil.TestDAO(Boolean bTestDelete) in C:\dev\xxxxx\NET3.0\NUnitTest\TestDAOUtil.cs:line 278
            at SimpleConsoleTest.Program.TestPeronDAO() in C:\dev\xxxxx\NET3.0\SimpleConsoleTest\Program.cs:line 131
            at SimpleConsoleTest.Program.Main() in C:\dev\xxxxx\NET3.0\SimpleConsoleTest\Program.cs:line 45
            at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
            at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
            at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
            at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
            at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
            at System.Threading.ThreadHelper.ThreadStart()
          {Inner Exception: NHibernate.ADOException: cannot open connection ---&amp;gt; System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
            at System.Data.Common.UnsafeNativeMethods.OraMTSEnlCtxGet(Byte[] lpUname, Byte[] lpPsswd, Byte[] lpDbnam, OciHandle pOCISvc, OciHandle pOCIErr, UInt32 dwFlags, IntPtr&amp;amp; pCtxt)
            at System.Data.OracleClient.TracedNativeMethods.OraMTSEnlCtxGet(Byte[] userName, Byte[] password, Byte[] serverName, OciHandle pOCISvc, OciHandle pOCIErr, IntPtr&amp;amp; pCtxt)
            at System.Data.OracleClient.OciEnlistContext..ctor(Byte[] userName, Byte[] password, Byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle)
            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 NHibernate.Connection.DriverConnectionProvider.GetConnection()
            at NHibernate.Impl.SessionFactoryImpl.OpenConnection()
            --- End of inner exception stack trace ---
            at NHibernate.Impl.SessionFactoryImpl.OpenConnection()
            at NHibernate.AdoNet.ConnectionManager.GetConnection()
            at NHibernate.AdoNet.AbstractBatcher.Prepare(IDbCommand cmd)
            at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
            at NHibernate.Id.SequenceGenerator.Generate(ISessionImplementor session, Object obj)
            at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
            at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
            at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
            at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
            at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
            at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
            at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
            at NHibernate.Impl.SessionImpl.Save(Object obj)
            &lt;b&gt;at xxxxx.Util.PersonDAO.Save(IGenericTO&amp;amp; oPerson) in C:\dev\xxxxx\NET3.0\Util\PersonDAO.cs:line 332 {Inner Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.&lt;/b&gt;
            at System.Data.Common.UnsafeNativeMethods.OraMTSEnlCtxGet(Byte[] lpUname, Byte[] lpPsswd, Byte[] lpDbnam, OciHandle pOCISvc, OciHandle pOCIErr, UInt32 dwFlags, IntPtr&amp;amp; pCtxt)
            at System.Data.OracleClient.TracedNativeMethods.OraMTSEnlCtxGet(Byte[] userName, Byte[] password, Byte[] serverName, OciHandle pOCISvc, OciHandle pOCIErr, IntPtr&amp;amp; pCtxt)
            at System.Data.OracleClient.OciEnlistContext..ctor(Byte[] userName, Byte[] password, Byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle)
            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 NHibernate.Connection.DriverConnectionProvider.GetConnection()
            at NHibernate.Impl.SessionFactoryImpl.OpenConnection()



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.