internal static void SafeDispose(ref OciServerHandle handle)
 {
     if (handle != null)
     {
         handle.Dispose();
     }
     handle = null;
 }
예제 #2
0
        internal void SetExtraInfo(OciErrorHandle errorHandle, OciServerHandle serverHandle)
        {
            _errorHandle = new HandleRef(this, errorHandle.Handle.Handle);  // OciHandle->HandleRef->IntPtr
            errorHandle.SetExternalOwnership();

            _serverHandle = new HandleRef(this, serverHandle.Handle.Handle);// OciHandle->HandleRef->IntPtr
            serverHandle.SetExternalOwnership();
        }
 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;
 }
        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);
        }