AccessViolationException when trying to insert a UDT

AccessViolationException when trying to insert a UDT

Postby PapaMufflon » Fri 06 Nov 2015 13:10

When issuing an insert command with a user defined type, I receive an AccessViolationException.

SQL
Code: Select all
CREATE TYPE CULTUREDEPENDENCY_OT AS OBJECT
(
  CULTURENAME NVARCHAR2(10),
  EVENTTEXT NVARCHAR2(1000),
  TITLE NVARCHAR2(100),
  CONTENT NVARCHAR2(2000),
  CONSEQUENCELEVEL NVARCHAR2(50)
)
/

CREATE TYPE CULTUREDEPENDENCIES_CT AS TABLE OF "CULTUREDEPENDENCY_OT";
/

CREATE TYPE PARAMETERDESCRIPTION_OT AS OBJECT
(
  "INDEX" NUMBER(10,0),
  "NAME" NVARCHAR2(200),
  "OBJECTTYPE" NVARCHAR2(200)
)
/

CREATE TYPE PARAMETERSDESCRIPTION_CT AS TABLE OF "PARAMETERDESCRIPTION_OT"
/

CREATE TYPE LOGEVENTDEFINITION_OT AS OBJECT
(
  "DBKEY" NUMBER(18,0),
  "LOGEVENTDEFINITIONID" RAW(16),
  "CREATED" DATE,
  "EVENTCODE" NVARCHAR2(100),
  "ISAUDITEVENT" NUMBER(1,0),
  "CONTAINSSENSITIVEDATA" NUMBER(1,0),
  "SEVERITY" NUMBER(10,0),
  "ISCONFIRMABLE" NUMBER(1,0),
  "SHOWCALLOUT" NUMBER(1,0),
  "PARAMETERSDESCRIPTION" PARAMETERSDESCRIPTION_CT,
  "CULTURES" CULTUREDEPENDENCIES_CT
)
/

CREATE TYPE "LOGEVENTDEFINITIONS_CT" AS TABLE OF "LOGEVENTDEFINITION_OT"
/


LogEventDefinition
Code: Select all
FUNCTION "INSERT_LOGEVENTDEFINITION" (
  "LOGEVENTDEF" IN "LOGEVENTDEFINITION_OT") RETURN NUMBER;


LOGEVENTDEFINITION_OT
Code: Select all
    public class LOGEVENTDEFINITION_OT : INullable, IOracleCustomType, IXmlSerializable
    {

        private bool m_IsNull;

        private byte[] m_LOGEVENTDEFINITIONID;

        private CULTUREDEPENDENCIES_CT m_CULTURES;

        private decimal m_SEVERITY;

        private bool m_SEVERITYIsNull;

        private string m_EVENTCODE;

        private bool m_EVENTCODEIsNull;

        private PARAMETERSDESCRIPTION_CT m_PARAMETERSDESCRIPTION;

        private decimal m_ISCONFIRMABLE;

        private bool m_ISCONFIRMABLEIsNull;

        private System.DateTime m_CREATED;

        private bool m_CREATEDIsNull;

        private decimal m_CONTAINSSENSITIVEDATA;

        private bool m_CONTAINSSENSITIVEDATAIsNull;

        private decimal m_ISAUDITEVENT;

        private bool m_ISAUDITEVENTIsNull;

        private decimal m_DBKEY;

        private bool m_DBKEYIsNull;

        private decimal m_SHOWCALLOUT;

        private bool m_SHOWCALLOUTIsNull;

        public LOGEVENTDEFINITION_OT()
        {
            this.m_SEVERITYIsNull = true;
            this.m_EVENTCODEIsNull = true;
            this.m_ISCONFIRMABLEIsNull = true;
            this.m_CREATEDIsNull = true;
            this.m_CONTAINSSENSITIVEDATAIsNull = true;
            this.m_ISAUDITEVENTIsNull = true;
            this.m_DBKEYIsNull = true;
            this.m_SHOWCALLOUTIsNull = true;
        }

        public LOGEVENTDEFINITION_OT(string str)
        {
        }

        public virtual bool IsNull
        {
            get
            {
                return this.m_IsNull;
            }
        }

        public static LOGEVENTDEFINITION_OT Null
        {
            get
            {
                LOGEVENTDEFINITION_OT obj = new LOGEVENTDEFINITION_OT();
                obj.m_IsNull = true;
                return obj;
            }
        }

        [OracleObjectMappingAttribute("LOGEVENTDEFINITIONID")]
        public byte[] LOGEVENTDEFINITIONID
        {
            get
            {
                return this.m_LOGEVENTDEFINITIONID;
            }
            set
            {
                this.m_LOGEVENTDEFINITIONID = value;
            }
        }

        [OracleObjectMappingAttribute("CULTURES")]
        public CULTUREDEPENDENCIES_CT CULTURES
        {
            get
            {
                return this.m_CULTURES;
            }
            set
            {
                this.m_CULTURES = value;
            }
        }

        [OracleObjectMappingAttribute("SEVERITY")]
        public decimal SEVERITY
        {
            get
            {
                return this.m_SEVERITY;
            }
            set
            {
                this.m_SEVERITY = value;
            }
        }

        public bool SEVERITYIsNull
        {
            get
            {
                return this.m_SEVERITYIsNull;
            }
            set
            {
                this.m_SEVERITYIsNull = value;
            }
        }

        [OracleObjectMappingAttribute("EVENTCODE")]
        public string EVENTCODE
        {
            get
            {
                return this.m_EVENTCODE;
            }
            set
            {
                this.m_EVENTCODE = value;
            }
        }

        public bool EVENTCODEIsNull
        {
            get
            {
                return this.m_EVENTCODEIsNull;
            }
            set
            {
                this.m_EVENTCODEIsNull = value;
            }
        }

        [OracleObjectMappingAttribute("PARAMETERSDESCRIPTION")]
        public PARAMETERSDESCRIPTION_CT PARAMETERSDESCRIPTION
        {
            get
            {
                return this.m_PARAMETERSDESCRIPTION;
            }
            set
            {
                this.m_PARAMETERSDESCRIPTION = value;
            }
        }

        [OracleObjectMappingAttribute("ISCONFIRMABLE")]
        public decimal ISCONFIRMABLE
        {
            get
            {
                return this.m_ISCONFIRMABLE;
            }
            set
            {
                this.m_ISCONFIRMABLE = value;
            }
        }

        public bool ISCONFIRMABLEIsNull
        {
            get
            {
                return this.m_ISCONFIRMABLEIsNull;
            }
            set
            {
                this.m_ISCONFIRMABLEIsNull = value;
            }
        }

        [OracleObjectMappingAttribute("CREATED")]
        public System.DateTime CREATED
        {
            get
            {
                return this.m_CREATED;
            }
            set
            {
                this.m_CREATED = value;
            }
        }

        public bool CREATEDIsNull
        {
            get
            {
                return this.m_CREATEDIsNull;
            }
            set
            {
                this.m_CREATEDIsNull = value;
            }
        }

        [OracleObjectMappingAttribute("CONTAINSSENSITIVEDATA")]
        public decimal CONTAINSSENSITIVEDATA
        {
            get
            {
                return this.m_CONTAINSSENSITIVEDATA;
            }
            set
            {
                this.m_CONTAINSSENSITIVEDATA = value;
            }
        }

        public bool CONTAINSSENSITIVEDATAIsNull
        {
            get
            {
                return this.m_CONTAINSSENSITIVEDATAIsNull;
            }
            set
            {
                this.m_CONTAINSSENSITIVEDATAIsNull = value;
            }
        }

        [OracleObjectMappingAttribute("ISAUDITEVENT")]
        public decimal ISAUDITEVENT
        {
            get
            {
                return this.m_ISAUDITEVENT;
            }
            set
            {
                this.m_ISAUDITEVENT = value;
            }
        }

        public bool ISAUDITEVENTIsNull
        {
            get
            {
                return this.m_ISAUDITEVENTIsNull;
            }
            set
            {
                this.m_ISAUDITEVENTIsNull = value;
            }
        }

        [OracleObjectMappingAttribute("DBKEY")]
        public decimal DBKEY
        {
            get
            {
                return this.m_DBKEY;
            }
            set
            {
                this.m_DBKEY = value;
            }
        }

        public bool DBKEYIsNull
        {
            get
            {
                return this.m_DBKEYIsNull;
            }
            set
            {
                this.m_DBKEYIsNull = value;
            }
        }

        [OracleObjectMappingAttribute("SHOWCALLOUT")]
        public decimal SHOWCALLOUT
        {
            get
            {
                return this.m_SHOWCALLOUT;
            }
            set
            {
                this.m_SHOWCALLOUT = value;
            }
        }

        public bool SHOWCALLOUTIsNull
        {
            get
            {
                return this.m_SHOWCALLOUTIsNull;
            }
            set
            {
                this.m_SHOWCALLOUTIsNull = value;
            }
        }

        public virtual void FromCustomObject(Oracle.DataAccess.Client.OracleConnection con, System.IntPtr pUdt)
        {
            Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "LOGEVENTDEFINITIONID", this.LOGEVENTDEFINITIONID);
            Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "CULTURES", this.CULTURES);
            if ((SEVERITYIsNull == false))
            {
                Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "SEVERITY", this.SEVERITY);
            }
            if ((EVENTCODEIsNull == false))
            {
                Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "EVENTCODE", this.EVENTCODE);
            }
            Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "PARAMETERSDESCRIPTION", this.PARAMETERSDESCRIPTION);
            if ((ISCONFIRMABLEIsNull == false))
            {
                Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "ISCONFIRMABLE", this.ISCONFIRMABLE);
            }
            if ((CREATEDIsNull == false))
            {
                Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "CREATED", this.CREATED);
            }
            if ((CONTAINSSENSITIVEDATAIsNull == false))
            {
                Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "CONTAINSSENSITIVEDATA", this.CONTAINSSENSITIVEDATA);
            }
            if ((ISAUDITEVENTIsNull == false))
            {
                Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "ISAUDITEVENT", this.ISAUDITEVENT);
            }
            if ((DBKEYIsNull == false))
            {
                Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "DBKEY", this.DBKEY);
            }
            if ((SHOWCALLOUTIsNull == false))
            {
                Oracle.DataAccess.Types.OracleUdt.SetValue(con, pUdt, "SHOWCALLOUT", this.SHOWCALLOUT);
            }
        }

        public virtual void ToCustomObject(Oracle.DataAccess.Client.OracleConnection con, System.IntPtr pUdt)
        {
            this.LOGEVENTDEFINITIONID = ((byte[])(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "LOGEVENTDEFINITIONID")));
            this.CULTURES = ((CULTUREDEPENDENCIES_CT)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "CULTURES")));
            this.SEVERITYIsNull = Oracle.DataAccess.Types.OracleUdt.IsDBNull(con, pUdt, "SEVERITY");
            if ((SEVERITYIsNull == false))
            {
                this.SEVERITY = ((decimal)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "SEVERITY")));
            }
            this.EVENTCODEIsNull = Oracle.DataAccess.Types.OracleUdt.IsDBNull(con, pUdt, "EVENTCODE");
            if ((EVENTCODEIsNull == false))
            {
                this.EVENTCODE = (string)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "EVENTCODE"));
            }
            this.PARAMETERSDESCRIPTION = ((PARAMETERSDESCRIPTION_CT)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "PARAMETERSDESCRIPTION")));
            this.ISCONFIRMABLEIsNull = Oracle.DataAccess.Types.OracleUdt.IsDBNull(con, pUdt, "ISCONFIRMABLE");
            if ((ISCONFIRMABLEIsNull == false))
            {
                this.ISCONFIRMABLE = ((decimal)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "ISCONFIRMABLE")));
            }
            this.CREATEDIsNull = Oracle.DataAccess.Types.OracleUdt.IsDBNull(con, pUdt, "CREATED");
            if ((CREATEDIsNull == false))
            {
                this.CREATED = ((System.DateTime)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "CREATED")));
            }
            this.CONTAINSSENSITIVEDATAIsNull = Oracle.DataAccess.Types.OracleUdt.IsDBNull(con, pUdt, "CONTAINSSENSITIVEDATA");
            if ((CONTAINSSENSITIVEDATAIsNull == false))
            {
                this.CONTAINSSENSITIVEDATA = ((decimal)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "CONTAINSSENSITIVEDATA")));
            }
            this.ISAUDITEVENTIsNull = Oracle.DataAccess.Types.OracleUdt.IsDBNull(con, pUdt, "ISAUDITEVENT");
            if ((ISAUDITEVENTIsNull == false))
            {
                this.ISAUDITEVENT = ((decimal)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "ISAUDITEVENT")));
            }
            this.DBKEYIsNull = Oracle.DataAccess.Types.OracleUdt.IsDBNull(con, pUdt, "DBKEY");
            if ((DBKEYIsNull == false))
            {
                this.DBKEY = ((decimal)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "DBKEY")));
            }
            this.SHOWCALLOUTIsNull = Oracle.DataAccess.Types.OracleUdt.IsDBNull(con, pUdt, "SHOWCALLOUT");
            if ((SHOWCALLOUTIsNull == false))
            {
                this.SHOWCALLOUT = ((decimal)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "SHOWCALLOUT")));
            }
        }

        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
        }

        public virtual void WriteXml(System.Xml.XmlWriter writer)
        {
        }

        public virtual XmlSchema GetSchema()
        {
            return null;
        }

        public override string ToString()
        {
            return "";
        }

        public static LOGEVENTDEFINITION_OT Parse(string str)
        {
            return new LOGEVENTDEFINITION_OT();
        }
    }


Failing Code
Code: Select all
            using (var command = new OracleCommand("LABCORE_LOGGING.INSERT_LOGEVENTDEFINITION"))
            {
                command.CommandType = CommandType.StoredProcedure;

                using (var connection = new OracleConnection(this.connectionString))
                {
                    connection.Open();

                    command.Connection = connection;

                    var value = new OracleObject("LOGEVENTDEFINITION_OT", connection);
                    value["DBKEY"] = definitionUdt.DBKEY;
                    value["LOGEVENTDEFINITIONID"] = definitionUdt.LOGEVENTDEFINITIONID;
                    value["CREATED"] = definitionUdt.CREATED;
                    value["EVENTCODE"] = definitionUdt.EVENTCODE;
                    value["ISAUDITEVENT"] = definitionUdt.ISAUDITEVENT;
                    value["CONTAINSSENSITIVEDATA"] = definitionUdt.CONTAINSSENSITIVEDATA;
                    value["SEVERITY"] = definitionUdt.SEVERITY;
                    value["ISCONFIRMABLE"] = definitionUdt.ISCONFIRMABLE;
                    value["SHOWCALLOUT"] = definitionUdt.SHOWCALLOUT;

                    var parameterDescription = new OracleTable(OracleType.GetObjectType("PARAMETERSDESCRIPTION_CT", connection));
                    definitionUdt.PARAMETERSDESCRIPTION.Value.Select(x =>
                    {
                        var foo = new OracleObject("PARAMETERDESCRIPTION_OT", connection);
                        foo["INDEX"] = x.INDEX;
                        foo["NAME"] = x.NAME;
                        foo["OBJECTTYPE"] = x.OBJECTTYPE;

                        return foo;
                    }).ToList().ForEach(x => parameterDescription.Add(x));

                    value["PARAMETERSDESCRIPTION"] = parameterDescription;

                    var cultures = new OracleTable(OracleType.GetObjectType("CULTUREDEPENDENCIES_CT", connection));
                    definitionUdt.CULTURES.Value.Select(x =>
                    {
                        var foo = new OracleObject("CULTUREDEPENDENCY_OT", connection);
                        foo["CULTURENAME"] = x.CULTURENAME;
                        foo["EVENTTEXT"] = x.EVENTTEXT;
                        foo["TITLE"] = x.TITLE;
                        foo["CONSEQUENCELEVEL"] = x.CONSEQUENCELEVEL;

                        return foo;
                    }).ToList().ForEach(x => cultures.Add(x));

                    value["CULTURES"] = cultures;


                    // prepare parameters "EVENTDEFINITION" and output parameter DBKey.
                    var parameter = new OracleParameter
                    {
                        ParameterName = "LOGEVENTDEFINITION",
                        OracleDbType = OracleDbType.Object,
                        Direction = ParameterDirection.Input,
                        ObjectTypeName = "LOGEVENTDEFINITION_OT",
                        Value = value
                    };

                    var resultParameter = new OracleParameter
                    {
                        ParameterName = "DBKEY",
                        OracleDbType = OracleDbType.Int64,
                        Direction = ParameterDirection.Output,
                        Value = value
                    };

                    command.Parameters.Add(parameter);
                    command.Parameters.Add(resultParameter);

                    command.ExecuteNonQuery();
                }
            }


On the last line, when executing the command, the following exception throws:

An unhandled exception of type 'System.AccessViolationException' occurred in Devart.Data.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source: OciCall.dll
StackTrace:
at OciDynamicType.nativeOCIObjectFree(HandleRef , HandleRef , HandleRef , Int16 )
at OciDynamicType.OCIObjectFree(HandleRef , HandleRef , HandleRef , Int16 )
at Devart.Data.Oracle.an.d()
at Devart.Data.Oracle.an.b(Boolean A_0)
at Devart.Data.Oracle.an.p()
at Devart.Data.Oracle.NativeOracleObjectBase.Dispose()
at Devart.Data.Oracle.OracleParameter.a()
at Devart.Data.Oracle.OracleCommand.b()
at Devart.Data.Oracle.OracleCommand.InternalExecute(CommandBehavior behavior, IDisposable disposable, Int32 startRecord, Int32 maxRecords, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at Devart.Data.Oracle.OracleCommand.ExecuteNonQuery()
at Logging.Services.LoggingDataAccessOracle.InsertNewEventDefinition(LOGEVENTDEFINITION_OT definitionUdt) in d:\src\Logging\Source\Logging.Services\LoggingDataAccessOracle.cs:line 249
at SyncInvokeStoreLogEvent(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceiveAsyncResult.OnReceive(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.OnReceiveComplete(Object state)
at System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state)
at System.ServiceModel.Channels.TracingConnection.TracingConnectionState.ExecuteCallback()
at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)


We're using version 8.4.359.0 of the dotConnect for Oracle and the DB is v11.

Anything I can do to make it work?
Last edited by PapaMufflon on Thu 12 Nov 2015 09:00, edited 1 time in total.
PapaMufflon
 
Posts: 2
Joined: Fri 06 Nov 2015 13:00

Re: AccessViolationException when trying to insert a UDT

Postby Pinturiccio » Tue 10 Nov 2015 12:45

Your snippet lacks the definition of the definitionUdt object. Please create and send us a complete test sample for reproducing the issue.

Your sample uses the stored procedure "LABCORE_LOGGING.INSERT_LOGEVENTDEFINITION", but we don't have its DDL script. Please send us the DDL script of the procedure and all the objects that are required to create and run it.
Pinturiccio
Devart Team
 
Posts: 1891
Joined: Wed 02 Nov 2011 09:44

Re: AccessViolationException when trying to insert a UDT

Postby PapaMufflon » Thu 12 Nov 2015 09:01

Sorry for that, I added the missing pieces.
PapaMufflon
 
Posts: 2
Joined: Fri 06 Nov 2015 13:00

Re: AccessViolationException when trying to insert a UDT

Postby Pinturiccio » Fri 13 Nov 2015 14:52

Unfortunately your code still is incomplete. The types CULTUREDEPENDENCIES_CT and PARAMETERSDESCRIPTION_CT are not included.

Please create a new project and add the code you posted on the forum to it. Compile the project and add all the necessary data for compiling and running the project. For example, we also don't know how the definitionUdt object is created, and which values are assigned to its fields.
Send us this project via our contact form.

PapaMufflon wrote:
Code: Select all
FUNCTION "INSERT_LOGEVENTDEFINITION" (
"LOGEVENTDEF" IN "LOGEVENTDEFINITION_OT") RETURN NUMBER;

This is just the function signature, please send us the script creating it, which contains the function body. If you don't want to post the function body on the forum, you may send it to us via our contact form.
Pinturiccio
Devart Team
 
Posts: 1891
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for Oracle