المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : System.Data.OracleClient - "System.AccessViolationException: Attempted to read or wri



C# Programming
04-09-2009, 05:25 AM
hello (First of all sorry about long stack trace)

I ran into this problem with System.Data.OracleClient - "System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

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/viewtopic.php?p=42223&sid=603c2d8bf01329ec2e98df036d5ef2da

I can't find anything "funny" with my Person's table.

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

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
/class


And here's application code:

public virtual long Save(ref IGenericTO oPerson)
{
...

try
{
// Wrapped in transaction scope
using (oScope = new TransactionScope())
{
DBSession.Flush();
// This is NHibernate ISession.Save - "System.AccessViolationException: exception here! (Works fine with M$SQL and MySQL)
nGeneratedId = (long)DBSession.Save(oPerson);
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/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=6003&wa=wsignin1.0

Any suggestion? Help!


REF:
http://forums.oracle.com/forums/thread.jspa?threadID=415053&tstart=0
http://www.devart.com/forums/viewtopic.php?p=42223&sid=603c2d8bf01329ec2e98df036d5ef2da
http://forums.asp.net/p/675515/675515.aspx

Sorry for long stack trace

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 counthttp://www.barakasoft.com/script/Forums/Images/smiley_redface.gif, 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& oPerson) in C:\dev\xxxxx\NET3.0\Util\PersonDAO.cs:line 349
at xxxxx.NUnitTest.TestDAOUtil.TestSaveAndSelectByKey(IGenericTO& 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 ---> 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& pCtxt)
at System.Data.OracleClient.TracedNativeMethods.OraMTSEnlCtxGet(Byte[] userName, Byte[] password, Byte[] serverName, OciHandle pOCISvc, OciHandle pOCIErr, IntPtr& 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(SaveOrUpdat eEvent 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)
at xxxxx.Util.PersonDAO.Save(IGenericTO& 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.
at System.Data.Common.UnsafeNativeMethods.OraMTSEnlCtxGet(Byte[] lpUname, Byte[] lpPsswd, Byte[] lpDbnam, OciHandle pOCISvc, OciHandle pOCIErr, UInt32 dwFlags, IntPtr& pCtxt)
at System.Data.OracleClient.TracedNativeMethods.OraMTSEnlCtxGet(Byte[] userName, Byte[] password, Byte[] serverName, OciHandle pOCISvc, OciHandle pOCIErr, IntPtr& 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()


dev

modified on Wednesday, April 8, 2009 9:20 PM