예제 #1
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;
        }
예제 #2
0
파일: OciGlue.cs 프로젝트: raj581/Marvin
        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;
        }
예제 #3
0
파일: OciGlue.cs 프로젝트: nlhepler/mono
		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 (!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;
		}