public void Disconnect() { if (session != null) { session.EndSession(error); session.Dispose(); session = null; } if (server != null) { server.Detach(error); server.Dispose(); server = null; } if (error != null) { error.Dispose(); error = null; } if (service != null) { service.Dispose(); service = null; } if (environment != null) { environment.Dispose(); environment = null; } }
public bool SetSession(OciSessionHandle handle) { session = handle; int status = OciCalls.OCIAttrSet(this, HandleType, session, 0, OciAttributeType.Session, ErrorHandle); return (status == 0); }
public void CreateConnection(OracleConnectionInfo conInfo) { environment = new OciEnvironmentHandle(OciEnvironmentMode.Threaded | OciEnvironmentMode.NoUserCallback); if (environment.Handle == IntPtr.Zero) { throw new OracleException(0, "Could not allocate the Oracle environment."); } service = (OciServiceHandle)environment.Allocate(OciHandleType.Service); if (service == null) { OciErrorInfo info = environment.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } error = (OciErrorHandle)environment.Allocate(OciHandleType.Error); if (error == null) { OciErrorInfo info = environment.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } service.ErrorHandle = error; server = (OciServerHandle)environment.Allocate(OciHandleType.Server); if (server == null) { OciErrorInfo info = environment.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } session = (OciSessionHandle)environment.Allocate(OciHandleType.Session); if (session == null) { OciErrorInfo info = environment.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } session.Username = conInfo.Username; session.Password = conInfo.Password; session.Service = service; if (!server.Attach(conInfo.Database, ErrorHandle)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } if (!service.SetServer(server)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } #if ORACLE_DATA_ACCESS if (conInfo.SetNewPassword == true) { // open with new password if (!service.SetSession(session)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } if (!service.ChangePassword(conInfo.NewPassword, error)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } conInfo.Password = conInfo.NewPassword; conInfo.SetNewPassword = false; conInfo.NewPassword = string.Empty; } else { #endif // open normally if (!session.BeginSession(conInfo.CredentialType, OciSessionMode.Default, ErrorHandle)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } if (!service.SetSession(session)) { OciErrorInfo info = error.HandleError(); Disconnect(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } #if ORACLE_DATA_ACCESS } #endif connected = true; }