internal OciEnlistContext(byte[] userName, byte[] password, byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle) : base(IntPtr.Zero, true)
 {
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
     }
     finally
     {
         this._serviceContextHandle = serviceContextHandle;
         int rc = 0;
         try
         {
             rc = TracedNativeMethods.OraMTSEnlCtxGet(userName, password, serverName, this._serviceContextHandle, errorHandle, out this.handle);
         }
         catch (DllNotFoundException exception)
         {
             throw System.Data.Common.ADP.DistribTxRequiresOracleServicesForMTS(exception);
         }
         if (rc != 0)
         {
             OracleException.Check(errorHandle, rc);
         }
         serviceContextHandle.AddRef();
     }
 }
コード例 #2
0
 internal OciEnlistContext(byte[] userName, byte[] password, byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle) : base(IntPtr.Zero, true)
 {
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
     }
     finally
     {
         this._serviceContextHandle = serviceContextHandle;
         int rc = 0;
         try
         {
             rc = TracedNativeMethods.OraMTSEnlCtxGet(userName, password, serverName, this._serviceContextHandle, errorHandle, out this.handle);
         }
         catch (DllNotFoundException exception)
         {
             throw System.Data.Common.ADP.DistribTxRequiresOracleServicesForMTS(exception);
         }
         if (rc != 0)
         {
             OracleException.Check(errorHandle, rc);
         }
         serviceContextHandle.AddRef();
     }
 }
コード例 #3
0
 internal static void SafeDispose(ref OciServiceContextHandle handle)
 {
     if (handle != null)
     {
         handle.Dispose();
     }
     handle = null;
 }
 protected override bool ReleaseHandle()
 {
     IntPtr handle = base.handle;
     base.handle = IntPtr.Zero;
     if (IntPtr.Zero != handle)
     {
         TracedNativeMethods.OraMTSEnlCtxRel(handle);
     }
     if (this._serviceContextHandle != null)
     {
         this._serviceContextHandle.Release();
         this._serviceContextHandle = null;
     }
     return true;
 }
コード例 #5
0
        protected override bool ReleaseHandle()
        {
            IntPtr handle = base.handle;

            base.handle = IntPtr.Zero;
            if (IntPtr.Zero != handle)
            {
                TracedNativeMethods.OraMTSEnlCtxRel(handle);
            }
            if (this._serviceContextHandle != null)
            {
                this._serviceContextHandle.Release();
                this._serviceContextHandle = null;
            }
            return(true);
        }
コード例 #6
0
        internal static OracleString GetPersistedRowid(OracleConnection connection, OciRowidDescriptor rowidHandle)
        {
            OracleString @null = OracleString.Null;

            if (rowidHandle != null)
            {
                OciErrorHandle errorHandle   = connection.ErrorHandle;
                NativeBuffer   scratchBuffer = connection.GetScratchBuffer(0xf82);
                bool           success       = false;
                bool           flag          = false;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    int num;
                    scratchBuffer.DangerousAddRef(ref success);
                    if (OCI.ClientVersionAtLeastOracle9i)
                    {
                        int length = scratchBuffer.Length;
                        num = TracedNativeMethods.OCIRowidToChar(rowidHandle, scratchBuffer, ref length, errorHandle);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        return(new OracleString(scratchBuffer.PtrToStringAnsi(0, length)));
                    }
                    rowidHandle.DangerousAddRef(ref flag);
                    OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle;
                    OciStatementHandle      stmtp = new OciStatementHandle(serviceContextHandle);
                    string stmt   = "begin :rowid := :rdesc; end;";
                    int    offset = 0;
                    int    num6   = 4;
                    int    num5   = 8;
                    int    num3   = 12;
                    int    num2   = 0x10;
                    int    num4   = 20;
                    try
                    {
                        IntPtr ptr;
                        IntPtr ptr2;
                        num = TracedNativeMethods.OCIStmtPrepare(stmtp, errorHandle, stmt, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, connection);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        scratchBuffer.WriteIntPtr(num5, rowidHandle.DangerousGetHandle());
                        scratchBuffer.WriteInt32(offset, 0);
                        scratchBuffer.WriteInt32(num6, 4);
                        scratchBuffer.WriteInt32(num3, 0);
                        scratchBuffer.WriteInt32(num2, 0xf6e);
                        num = TracedNativeMethods.OCIBindByName(stmtp, out ptr2, errorHandle, "rowid", 5, scratchBuffer.DangerousGetDataPtr(num4), 0xf6e, OCI.DATATYPE.VARCHAR2, scratchBuffer.DangerousGetDataPtr(num3), scratchBuffer.DangerousGetDataPtr(num2), OCI.MODE.OCI_DEFAULT);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        num = TracedNativeMethods.OCIBindByName(stmtp, out ptr, errorHandle, "rdesc", 5, scratchBuffer.DangerousGetDataPtr(num5), 4, OCI.DATATYPE.ROWID_DESC, scratchBuffer.DangerousGetDataPtr(offset), scratchBuffer.DangerousGetDataPtr(num6), OCI.MODE.OCI_DEFAULT);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        num = TracedNativeMethods.OCIStmtExecute(serviceContextHandle, stmtp, errorHandle, 1, OCI.MODE.OCI_DEFAULT);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        if (scratchBuffer.ReadInt16(num3) == -1)
                        {
                            return(@null);
                        }
                        @null = new OracleString(scratchBuffer, num4, num2, MetaType.GetMetaTypeForType(OracleType.RowId), connection, false, true);
                        GC.KeepAlive(rowidHandle);
                    }
                    finally
                    {
                        OciHandle.SafeDispose(ref stmtp);
                    }
                }
                finally
                {
                    if (flag)
                    {
                        rowidHandle.DangerousRelease();
                    }
                    if (success)
                    {
                        scratchBuffer.DangerousRelease();
                    }
                }
            }
            return(@null);
        }
 private bool OpenOnLocalTransaction(string userName, string password, string serverName, bool integratedSecurity, bool unicode, bool omitOracleConnectionName)
 {
     int rc = 0;
     OCI.MODE environmentMode = OCI.MODE.OCI_DATA_AT_EXEC | OCI.MODE.OCI_BATCH_MODE;
     OCI.DetermineClientVersion();
     if (unicode)
     {
         if (OCI.ClientVersionAtLeastOracle9i)
         {
             environmentMode |= OCI.MODE.OCI_UTF16;
         }
         else
         {
             unicode = false;
         }
     }
     this._environmentHandle = new OciEnvironmentHandle(environmentMode, unicode);
     if (this._environmentHandle.IsInvalid)
     {
         throw System.Data.Common.ADP.CouldNotCreateEnvironment("OCIEnvCreate", rc);
     }
     this._errorHandle = new OciErrorHandle(this._environmentHandle);
     this._serverHandle = new OciServerHandle(this._errorHandle);
     this._sessionHandle = new OciSessionHandle(this._serverHandle);
     this._serviceContextHandle = new OciServiceContextHandle(this._sessionHandle);
     try
     {
         OCI.CRED cred;
         rc = TracedNativeMethods.OCIServerAttach(this._serverHandle, this._errorHandle, serverName, serverName.Length, OCI.MODE.OCI_DEFAULT);
         if (rc != 0)
         {
             if (1 == rc)
             {
                 this.CreateDeferredInfoMessage(this.ErrorHandle, rc);
             }
             else
             {
                 OracleException.Check(this.ErrorHandle, rc);
             }
         }
         this._serviceContextHandle.SetAttribute(OCI.ATTR.OCI_ATTR_SERVER, this._serverHandle, this._errorHandle);
         if (integratedSecurity)
         {
             cred = OCI.CRED.OCI_CRED_EXT;
         }
         else
         {
             cred = OCI.CRED.OCI_CRED_RDBMS;
             this._sessionHandle.SetAttribute(OCI.ATTR.OCI_ATTR_USERNAME, userName, this._errorHandle);
             if (password != null)
             {
                 this._sessionHandle.SetAttribute(OCI.ATTR.OCI_ATTR_PASSWORD, password, this._errorHandle);
             }
         }
         if (!omitOracleConnectionName)
         {
             string dataSource = this._connectionOptions.DataSource;
             if (dataSource.Length > 0x10)
             {
                 dataSource = dataSource.Substring(0, 0x10);
             }
             this._serverHandle.SetAttribute(OCI.ATTR.OCI_ATTR_EXTERNAL_NAME, dataSource, this._errorHandle);
             this._serverHandle.SetAttribute(OCI.ATTR.OCI_ATTR_INTERNAL_NAME, dataSource, this._errorHandle);
         }
         rc = TracedNativeMethods.OCISessionBegin(this._serviceContextHandle, this._errorHandle, this._sessionHandle, cred, OCI.MODE.OCI_DEFAULT);
         if (rc != 0)
         {
             if (1 == rc)
             {
                 this.CreateDeferredInfoMessage(this.ErrorHandle, rc);
             }
             else
             {
                 OracleException.Check(this.ErrorHandle, rc);
             }
         }
         this._serviceContextHandle.SetAttribute(OCI.ATTR.OCI_ATTR_SESSION, this._sessionHandle, this._errorHandle);
     }
     catch (OracleException)
     {
         OciHandle.SafeDispose(ref this._serviceContextHandle);
         OciHandle.SafeDispose(ref this._sessionHandle);
         OciHandle.SafeDispose(ref this._serverHandle);
         OciHandle.SafeDispose(ref this._errorHandle);
         OciHandle.SafeDispose(ref this._environmentHandle);
         throw;
     }
     return true;
 }
コード例 #8
0
        private bool OpenOnLocalTransaction(string userName, string password, string serverName, bool integratedSecurity, bool unicode, bool omitOracleConnectionName)
        {
            int rc = 0;

            OCI.MODE environmentMode = OCI.MODE.OCI_DATA_AT_EXEC | OCI.MODE.OCI_BATCH_MODE;
            OCI.DetermineClientVersion();
            if (unicode)
            {
                if (OCI.ClientVersionAtLeastOracle9i)
                {
                    environmentMode |= OCI.MODE.OCI_UTF16;
                }
                else
                {
                    unicode = false;
                }
            }
            this._environmentHandle = new OciEnvironmentHandle(environmentMode, unicode);
            if (this._environmentHandle.IsInvalid)
            {
                throw System.Data.Common.ADP.CouldNotCreateEnvironment("OCIEnvCreate", rc);
            }
            this._errorHandle          = new OciErrorHandle(this._environmentHandle);
            this._serverHandle         = new OciServerHandle(this._errorHandle);
            this._sessionHandle        = new OciSessionHandle(this._serverHandle);
            this._serviceContextHandle = new OciServiceContextHandle(this._sessionHandle);
            try
            {
                OCI.CRED cred;
                rc = TracedNativeMethods.OCIServerAttach(this._serverHandle, this._errorHandle, serverName, serverName.Length, OCI.MODE.OCI_DEFAULT);
                if (rc != 0)
                {
                    if (1 == rc)
                    {
                        this.CreateDeferredInfoMessage(this.ErrorHandle, rc);
                    }
                    else
                    {
                        OracleException.Check(this.ErrorHandle, rc);
                    }
                }
                this._serviceContextHandle.SetAttribute(OCI.ATTR.OCI_ATTR_SERVER, this._serverHandle, this._errorHandle);
                if (integratedSecurity)
                {
                    cred = OCI.CRED.OCI_CRED_EXT;
                }
                else
                {
                    cred = OCI.CRED.OCI_CRED_RDBMS;
                    this._sessionHandle.SetAttribute(OCI.ATTR.OCI_ATTR_USERNAME, userName, this._errorHandle);
                    if (password != null)
                    {
                        this._sessionHandle.SetAttribute(OCI.ATTR.OCI_ATTR_PASSWORD, password, this._errorHandle);
                    }
                }
                if (!omitOracleConnectionName)
                {
                    string dataSource = this._connectionOptions.DataSource;
                    if (dataSource.Length > 0x10)
                    {
                        dataSource = dataSource.Substring(0, 0x10);
                    }
                    this._serverHandle.SetAttribute(OCI.ATTR.OCI_ATTR_EXTERNAL_NAME, dataSource, this._errorHandle);
                    this._serverHandle.SetAttribute(OCI.ATTR.OCI_ATTR_INTERNAL_NAME, dataSource, this._errorHandle);
                }
                rc = TracedNativeMethods.OCISessionBegin(this._serviceContextHandle, this._errorHandle, this._sessionHandle, cred, OCI.MODE.OCI_DEFAULT);
                if (rc != 0)
                {
                    if (1 == rc)
                    {
                        this.CreateDeferredInfoMessage(this.ErrorHandle, rc);
                    }
                    else
                    {
                        OracleException.Check(this.ErrorHandle, rc);
                    }
                }
                this._serviceContextHandle.SetAttribute(OCI.ATTR.OCI_ATTR_SESSION, this._sessionHandle, this._errorHandle);
            }
            catch (OracleException)
            {
                OciHandle.SafeDispose(ref this._serviceContextHandle);
                OciHandle.SafeDispose(ref this._sessionHandle);
                OciHandle.SafeDispose(ref this._serverHandle);
                OciHandle.SafeDispose(ref this._errorHandle);
                OciHandle.SafeDispose(ref this._environmentHandle);
                throw;
            }
            return(true);
        }
コード例 #9
0
        internal void Bind(OciStatementHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection, ref bool mustRelease, ref SafeHandle handleToBind)
        {
            if (IsDirection(this.Parameter, ParameterDirection.Output) || (this.Parameter.Value != null))
            {
                int                     num2;
                IntPtr                  ptr2;
                string                  parameterName        = this.Parameter.ParameterName;
                OciErrorHandle          errorHandle          = connection.ErrorHandle;
                OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle;
                int                     num     = 0;
                OCI.INDICATOR           oK      = OCI.INDICATOR.OK;
                OCI.DATATYPE            ociType = this._bindingMetaType.OciType;
                IntPtr                  dataPtr = parameterBuffer.DangerousGetDataPtr(this._indicatorOffset);
                IntPtr                  alenp   = parameterBuffer.DangerousGetDataPtr(this._lengthOffset);
                IntPtr                  valuep  = parameterBuffer.DangerousGetDataPtr(this._valueOffset);
                OciHandle.SafeDispose(ref this._dateTimeDescriptor);
                if (IsDirection(this.Parameter, ParameterDirection.Input))
                {
                    if (System.Data.Common.ADP.IsNull(this._coercedValue))
                    {
                        oK = OCI.INDICATOR.ISNULL;
                        switch (ociType)
                        {
                        case OCI.DATATYPE.INT_TIMESTAMP:
                        case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                        case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                            this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                            handleToBind             = this._dateTimeDescriptor;
                            break;
                        }
                    }
                    else
                    {
                        num = this.PutOracleValue(this._coercedValue, parameterBuffer, this._valueOffset, this._bindingMetaType, connection, ref handleToBind);
                    }
                }
                else
                {
                    if (this._bindingMetaType.IsVariableLength)
                    {
                        num = 0;
                    }
                    else
                    {
                        num = this._bufferLength;
                    }
                    OciLobLocator.SafeDispose(ref this._locator);
                    OciHandle.SafeDispose(ref this._descriptor);
                    switch (ociType)
                    {
                    case OCI.DATATYPE.CLOB:
                    case OCI.DATATYPE.BLOB:
                    case OCI.DATATYPE.BFILE:
                        this._locator = new OciLobLocator(connection, this._bindingMetaType.OracleType);
                        handleToBind  = this._locator.Descriptor;
                        break;

                    case OCI.DATATYPE.RSET:
                        this._descriptor = new OciStatementHandle(serviceContextHandle);
                        handleToBind     = this._descriptor;
                        break;

                    case OCI.DATATYPE.INT_TIMESTAMP:
                    case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                    case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                        this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                        handleToBind             = this._dateTimeDescriptor;
                        break;
                    }
                }
                if (handleToBind != null)
                {
                    handleToBind.DangerousAddRef(ref mustRelease);
                    parameterBuffer.WriteIntPtr(this._valueOffset, handleToBind.DangerousGetHandle());
                }
                parameterBuffer.WriteInt16(this._indicatorOffset, (short)oK);
                if ((OCI.DATATYPE.LONGVARCHAR == ociType) || (OCI.DATATYPE.LONGVARRAW == ociType))
                {
                    alenp = IntPtr.Zero;
                }
                else if (this._bindAsUCS2)
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num / System.Data.Common.ADP.CharSize);
                }
                else
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num);
                }
                if (IsDirection(this.Parameter, ParameterDirection.Output))
                {
                    num2 = this._bufferLength;
                }
                else
                {
                    num2 = num;
                }
                OCI.DATATYPE dty = ociType;
                switch (ociType)
                {
                case OCI.DATATYPE.INT_TIMESTAMP:
                    dty = OCI.DATATYPE.TIMESTAMP;
                    break;

                case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                    dty = OCI.DATATYPE.TIMESTAMP_TZ;
                    break;

                case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                    dty = OCI.DATATYPE.TIMESTAMP_LTZ;
                    break;
                }
                int rc = TracedNativeMethods.OCIBindByName(statementHandle, out ptr2, errorHandle, parameterName, parameterName.Length, valuep, num2, dty, dataPtr, alenp, OCI.MODE.OCI_DEFAULT);
                if (rc != 0)
                {
                    this._command.Connection.CheckError(errorHandle, rc);
                }
                this._bindHandle = new OciBindHandle(statementHandle, ptr2);
                if (this._bindingMetaType.IsCharacterType)
                {
                    if (OCI.ClientVersionAtLeastOracle9i && IsDirection(this.Parameter, ParameterDirection.Output))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXCHAR_SIZE, this._bindSize, errorHandle);
                    }
                    if ((num2 > (this._bindingMetaType.MaxBindSize / System.Data.Common.ADP.CharSize)) || (!OCI.ClientVersionAtLeastOracle9i && this._bindingMetaType.UsesNationalCharacterSet))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXDATA_SIZE, this._bindingMetaType.MaxBindSize, errorHandle);
                    }
                    if (this._bindingMetaType.UsesNationalCharacterSet)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, 2, errorHandle);
                    }
                    if (this._bindAsUCS2)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, 0x3e8, errorHandle);
                    }
                }
                GC.KeepAlive(parameterBuffer);
            }
        }