Пример #1
0
 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;
     }
 }
Пример #2
0
		public bool SetServer (OciServerHandle handle)
		{
			server = handle;
			int status = OciCalls.OCIAttrSet (this,
							HandleType,
							server,
							0,
							OciAttributeType.Server,
							ErrorHandle);
			return (status == 0);
		}
Пример #3
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;
        }
Пример #4
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;
		}
Пример #5
0
		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;
			}
		}
Пример #6
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 (!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);
            }

            connected = true;
        }
Пример #7
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 (!session.BeginSession (OciCredentialType.RDBMS, 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);
			}

			connected = true;
		}