internal static void SafeDispose(ref OciEnvironmentHandle handle) { if (handle != null) { handle.Dispose(); } handle = null; }
private static void Initialize() { lock (locked) { if (!isInitialized) { bool unicode = false; OCI.MODE environmentMode = OCI.MODE.OCI_DATA_AT_EXEC | OCI.MODE.OCI_BATCH_MODE; OCI.DetermineClientVersion(); environmentHandle = new OciEnvironmentHandle(environmentMode, unicode); availableErrorHandle = new OciErrorHandle(environmentHandle); isInitialized = true; } } }
internal static int DetermineClientVersion() { if (_clientVersion == 0) { int num = 0; MODE environmentMode = MODE.OCI_DATA_AT_EXEC | MODE.OCI_BATCH_MODE; try { System.Data.Common.UnsafeNativeMethods.OCILobCopy2(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0L, 0L, 0L); num = 0x65; } catch (EntryPointNotFoundException exception6) { System.Data.Common.ADP.TraceException(exception6); try { OciHandle handle = new OciNlsEnvironmentHandle(environmentMode); if (!handle.IsInvalid) { num = 0x5c; OciHandle.SafeDispose(ref handle); } } catch (EntryPointNotFoundException exception5) { System.Data.Common.ADP.TraceException(exception5); try { environmentMode |= MODE.OCI_UTF16; OciHandle handle2 = new OciEnvironmentHandle(environmentMode, true); num = 90; OciHandle.SafeDispose(ref handle2); } catch (EntryPointNotFoundException exception4) { System.Data.Common.ADP.TraceException(exception4); num = 80; } catch (Exception exception) { if (!System.Data.Common.ADP.IsCatchableExceptionType(exception)) { throw; } System.Data.Common.ADP.TraceException(exception); num = 0x51; } } } catch (DllNotFoundException exception3) { System.Data.Common.ADP.TraceException(exception3); num = 0x49; } catch (BadImageFormatException exception2) { throw System.Data.Common.ADP.BadOracleClientImageFormat(exception2); } if (0x51 > num) { throw System.Data.Common.ADP.BadOracleClientVersion(); } _clientVersion = num; } return(_clientVersion); }
internal static int DetermineClientVersion() { if (_clientVersion == 0) { int num = 0; MODE environmentMode = MODE.OCI_DATA_AT_EXEC | MODE.OCI_BATCH_MODE; try { System.Data.Common.UnsafeNativeMethods.OCILobCopy2(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0L, 0L, 0L); num = 0x65; } catch (EntryPointNotFoundException exception6) { System.Data.Common.ADP.TraceException(exception6); try { OciHandle handle = new OciNlsEnvironmentHandle(environmentMode); if (!handle.IsInvalid) { num = 0x5c; OciHandle.SafeDispose(ref handle); } } catch (EntryPointNotFoundException exception5) { System.Data.Common.ADP.TraceException(exception5); try { environmentMode |= MODE.OCI_UTF16; OciHandle handle2 = new OciEnvironmentHandle(environmentMode, true); num = 90; OciHandle.SafeDispose(ref handle2); } catch (EntryPointNotFoundException exception4) { System.Data.Common.ADP.TraceException(exception4); num = 80; } catch (Exception exception) { if (!System.Data.Common.ADP.IsCatchableExceptionType(exception)) { throw; } System.Data.Common.ADP.TraceException(exception); num = 0x51; } } } catch (DllNotFoundException exception3) { System.Data.Common.ADP.TraceException(exception3); num = 0x49; } catch (BadImageFormatException exception2) { throw System.Data.Common.ADP.BadOracleClientImageFormat(exception2); } if (0x51 > num) { throw System.Data.Common.ADP.BadOracleClientVersion(); } _clientVersion = num; } return _clientVersion; }
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); }