OracleConnectionString.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / DataOracleClient / System / Data / OracleClient / OracleConnectionString.cs / 1 / OracleConnectionString.cs

                            //------------------------------------------------------------------------------ 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
// [....]
//----------------------------------------------------------------------------- 
 
namespace System.Data.OracleClient {
 
    using System;
    using System.Collections;
    using System.Data;
    using System.Data.Common; 
    using System.Diagnostics;
 
    internal sealed class OracleConnectionString : DbConnectionOptions { 
        // instances of this class are intended to be immutable, i.e readonly
        // used by pooling classes so it is much easier to verify correctness 
        // when not worried about the class being modified during execution

        static internal class DEFAULT {
            internal const int      Load_Balance_Timeout     = 0; // default of 0 means don't use 
            internal const string   Data_Source              = "";
            internal const bool     Enlist                   = true; 
            internal const bool     Integrated_Security      = false; 
            internal const int      Max_Pool_Size            = 100;
            internal const int      Min_Pool_Size            = 0; 
            internal const string   Password                 = "";
            internal const bool     Persist_Security_Info    = false;
            internal const bool     Pooling                  = true;
            internal const bool     Unicode                  = false; 
            internal const string   User_ID                  = "";
            internal const bool     OmitOracleConnectionName = false; 
        }; 

        static internal class KEY { 
            internal const string Data_Source              = "data source";
            internal const string Enlist                   = "enlist";
            internal const string Integrated_Security      = "integrated security";
            internal const string Load_Balance_Timeout     = "load balance timeout"; 
            internal const string Max_Pool_Size            = "max pool size";
            internal const string Min_Pool_Size            = "min pool size"; 
            internal const string Password                 = "password"; 
            internal const string Persist_Security_Info    = "persist security info";
            internal const string Pooling                  = "pooling"; 
            internal const string Unicode                  = "unicode";
            internal const string User_ID                  = "user id";
            internal const string OmitOracleConnectionName = "omit oracle connection name";
        }; 

        static internal class SYNONYM { 
            internal const string SERVER                    = "server";                 // data source 
            internal const string Pwd                       = "pwd";                    // password
            internal const string PERSISTSECURITYINFO       = "persistsecurityinfo";    // persist security info 
            internal const string UID                       = "uid";                    // user id
            internal const string User                      = "user";                   // user id
            internal const string Connection_Lifetime       = "connection lifetime";    // load balancing timeout
            internal const string WorkaroundOracleBug914652 = "workaround oracle bug 914652"; 
        };
 
 
        private static Hashtable            _validKeyNamesAndSynonyms;
 
        private readonly bool               _enlist;
        private readonly bool               _integratedSecurity;
        private readonly bool               _persistSecurityInfo;
        private readonly bool               _pooling; 
        private readonly bool               _unicode;
        private readonly bool               _omitOracleConnectionName; 
 
        private readonly int                _loadBalanceTimeout;
        private readonly int                _maxPoolSize; 
        private readonly int                _minPoolSize;

        private readonly string             _dataSource;
        private readonly string             _password; 
        private readonly string             _userId;
 
        public OracleConnectionString(string connectionString) 
            : base(connectionString, GetParseSynonyms(), false) {
            _integratedSecurity = ConvertValueToIntegratedSecurity(); 

            _enlist             = ConvertValueToBoolean(KEY.Enlist,                 ADP.IsWindowsNT);

            _persistSecurityInfo= ConvertValueToBoolean(KEY.Persist_Security_Info,  DEFAULT.Persist_Security_Info); 
            _pooling            = ConvertValueToBoolean(KEY.Pooling,                DEFAULT.Pooling);
            _unicode            = ConvertValueToBoolean(KEY.Unicode,                DEFAULT.Unicode); 
            _omitOracleConnectionName = ConvertValueToBoolean(KEY.OmitOracleConnectionName, DEFAULT.OmitOracleConnectionName); 

            _loadBalanceTimeout = ConvertValueToInt32(KEY.Load_Balance_Timeout,     DEFAULT.Load_Balance_Timeout); 
            _maxPoolSize        = ConvertValueToInt32(KEY.Max_Pool_Size,            DEFAULT.Max_Pool_Size);
            _minPoolSize        = ConvertValueToInt32(KEY.Min_Pool_Size,            DEFAULT.Min_Pool_Size);

            _dataSource         = ConvertValueToString(KEY.Data_Source,             DEFAULT.Data_Source); 
            _userId             = ConvertValueToString(KEY.User_ID,                 DEFAULT.User_ID);
            _password           = ConvertValueToString(KEY.Password,                DEFAULT.Password); 
 
            if (_userId.Length > 30)
                throw ADP.InvalidConnectionOptionLength(KEY.User_ID, 30); 

            if (_password.Length > 30)
                throw ADP.InvalidConnectionOptionLength(KEY.Password, 30);
 
            if (_loadBalanceTimeout < 0)
                throw ADP.InvalidConnectionOptionValue(KEY.Load_Balance_Timeout); 
 
            if (_maxPoolSize < 1)
                throw ADP.InvalidConnectionOptionValue(KEY.Max_Pool_Size); 

            if (_minPoolSize < 0)
                throw ADP.InvalidConnectionOptionValue(KEY.Min_Pool_Size);
 
            if (_maxPoolSize < _minPoolSize)
                throw ADP.InvalidMinMaxPoolSizeValues(); 
        } 

        internal bool   Enlist              { get { return _enlist; } } 
        internal bool   IntegratedSecurity  { get { return _integratedSecurity; } }
        //internal bool   PersistSecurityInfo { get { return _persistSecurityInfo; } }
        internal bool   Pooling             { get { return _pooling; } }
        internal bool   Unicode             { get { return _unicode; } } 
        internal bool   OmitOracleConnectionName  { get { return _omitOracleConnectionName; } }
 
        internal int    LoadBalanceTimeout  { get { return _loadBalanceTimeout; } } 
        internal int    MaxPoolSize         { get { return _maxPoolSize; } }
        internal int    MinPoolSize         { get { return _minPoolSize; } } 

        internal string DataSource          { get { return _dataSource; } }
        internal string UserId              { get { return _userId; } }
        internal string Password            { get { return _password; } } 

        protected internal override System.Security.PermissionSet CreatePermissionSet() { 
            System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None); 
            permissionSet.AddPermission(new OraclePermission(this));
            return permissionSet; 
        }

        // this hashtable is meant to be read-only translation of parsed string
        // keywords/synonyms to a known keyword string 
        internal static Hashtable GetParseSynonyms() {
            const int KeyCount = 12; 
            const int SynonymCount = 7; 

            Hashtable hash = _validKeyNamesAndSynonyms; 
            if (null == hash) {
                hash = new Hashtable(KeyCount + SynonymCount);
                hash.Add(KEY.Data_Source,                   KEY.Data_Source);
                hash.Add(KEY.Enlist,                        KEY.Enlist); 
                hash.Add(KEY.Integrated_Security,           KEY.Integrated_Security);
                hash.Add(KEY.Load_Balance_Timeout,          KEY.Load_Balance_Timeout); 
                hash.Add(KEY.Max_Pool_Size,                 KEY.Max_Pool_Size); 
                hash.Add(KEY.Min_Pool_Size,                 KEY.Min_Pool_Size);
                hash.Add(KEY.OmitOracleConnectionName,      KEY.OmitOracleConnectionName); 
                hash.Add(KEY.Password,                      KEY.Password);
                hash.Add(KEY.Persist_Security_Info,         KEY.Persist_Security_Info);
                hash.Add(KEY.Pooling,                       KEY.Pooling);
                hash.Add(KEY.Unicode,                       KEY.Unicode); 
                hash.Add(KEY.User_ID,                       KEY.User_ID);
 
                hash.Add(SYNONYM.SERVER,                    KEY.Data_Source); 
                hash.Add(SYNONYM.Pwd,                       KEY.Password);
                hash.Add(SYNONYM.PERSISTSECURITYINFO,       KEY.Persist_Security_Info); 
                hash.Add(SYNONYM.UID,                       KEY.User_ID);
                hash.Add(SYNONYM.User,                      KEY.User_ID);
                hash.Add(SYNONYM.Connection_Lifetime,       KEY.Load_Balance_Timeout);
                hash.Add(SYNONYM.WorkaroundOracleBug914652, KEY.OmitOracleConnectionName); 
                Debug.Assert(KeyCount + SynonymCount == hash.Count, "incorrect initial ParseSynonyms size");
                _validKeyNamesAndSynonyms = hash; 
            } 
            return hash;
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
// [....]
//----------------------------------------------------------------------------- 
 
namespace System.Data.OracleClient {
 
    using System;
    using System.Collections;
    using System.Data;
    using System.Data.Common; 
    using System.Diagnostics;
 
    internal sealed class OracleConnectionString : DbConnectionOptions { 
        // instances of this class are intended to be immutable, i.e readonly
        // used by pooling classes so it is much easier to verify correctness 
        // when not worried about the class being modified during execution

        static internal class DEFAULT {
            internal const int      Load_Balance_Timeout     = 0; // default of 0 means don't use 
            internal const string   Data_Source              = "";
            internal const bool     Enlist                   = true; 
            internal const bool     Integrated_Security      = false; 
            internal const int      Max_Pool_Size            = 100;
            internal const int      Min_Pool_Size            = 0; 
            internal const string   Password                 = "";
            internal const bool     Persist_Security_Info    = false;
            internal const bool     Pooling                  = true;
            internal const bool     Unicode                  = false; 
            internal const string   User_ID                  = "";
            internal const bool     OmitOracleConnectionName = false; 
        }; 

        static internal class KEY { 
            internal const string Data_Source              = "data source";
            internal const string Enlist                   = "enlist";
            internal const string Integrated_Security      = "integrated security";
            internal const string Load_Balance_Timeout     = "load balance timeout"; 
            internal const string Max_Pool_Size            = "max pool size";
            internal const string Min_Pool_Size            = "min pool size"; 
            internal const string Password                 = "password"; 
            internal const string Persist_Security_Info    = "persist security info";
            internal const string Pooling                  = "pooling"; 
            internal const string Unicode                  = "unicode";
            internal const string User_ID                  = "user id";
            internal const string OmitOracleConnectionName = "omit oracle connection name";
        }; 

        static internal class SYNONYM { 
            internal const string SERVER                    = "server";                 // data source 
            internal const string Pwd                       = "pwd";                    // password
            internal const string PERSISTSECURITYINFO       = "persistsecurityinfo";    // persist security info 
            internal const string UID                       = "uid";                    // user id
            internal const string User                      = "user";                   // user id
            internal const string Connection_Lifetime       = "connection lifetime";    // load balancing timeout
            internal const string WorkaroundOracleBug914652 = "workaround oracle bug 914652"; 
        };
 
 
        private static Hashtable            _validKeyNamesAndSynonyms;
 
        private readonly bool               _enlist;
        private readonly bool               _integratedSecurity;
        private readonly bool               _persistSecurityInfo;
        private readonly bool               _pooling; 
        private readonly bool               _unicode;
        private readonly bool               _omitOracleConnectionName; 
 
        private readonly int                _loadBalanceTimeout;
        private readonly int                _maxPoolSize; 
        private readonly int                _minPoolSize;

        private readonly string             _dataSource;
        private readonly string             _password; 
        private readonly string             _userId;
 
        public OracleConnectionString(string connectionString) 
            : base(connectionString, GetParseSynonyms(), false) {
            _integratedSecurity = ConvertValueToIntegratedSecurity(); 

            _enlist             = ConvertValueToBoolean(KEY.Enlist,                 ADP.IsWindowsNT);

            _persistSecurityInfo= ConvertValueToBoolean(KEY.Persist_Security_Info,  DEFAULT.Persist_Security_Info); 
            _pooling            = ConvertValueToBoolean(KEY.Pooling,                DEFAULT.Pooling);
            _unicode            = ConvertValueToBoolean(KEY.Unicode,                DEFAULT.Unicode); 
            _omitOracleConnectionName = ConvertValueToBoolean(KEY.OmitOracleConnectionName, DEFAULT.OmitOracleConnectionName); 

            _loadBalanceTimeout = ConvertValueToInt32(KEY.Load_Balance_Timeout,     DEFAULT.Load_Balance_Timeout); 
            _maxPoolSize        = ConvertValueToInt32(KEY.Max_Pool_Size,            DEFAULT.Max_Pool_Size);
            _minPoolSize        = ConvertValueToInt32(KEY.Min_Pool_Size,            DEFAULT.Min_Pool_Size);

            _dataSource         = ConvertValueToString(KEY.Data_Source,             DEFAULT.Data_Source); 
            _userId             = ConvertValueToString(KEY.User_ID,                 DEFAULT.User_ID);
            _password           = ConvertValueToString(KEY.Password,                DEFAULT.Password); 
 
            if (_userId.Length > 30)
                throw ADP.InvalidConnectionOptionLength(KEY.User_ID, 30); 

            if (_password.Length > 30)
                throw ADP.InvalidConnectionOptionLength(KEY.Password, 30);
 
            if (_loadBalanceTimeout < 0)
                throw ADP.InvalidConnectionOptionValue(KEY.Load_Balance_Timeout); 
 
            if (_maxPoolSize < 1)
                throw ADP.InvalidConnectionOptionValue(KEY.Max_Pool_Size); 

            if (_minPoolSize < 0)
                throw ADP.InvalidConnectionOptionValue(KEY.Min_Pool_Size);
 
            if (_maxPoolSize < _minPoolSize)
                throw ADP.InvalidMinMaxPoolSizeValues(); 
        } 

        internal bool   Enlist              { get { return _enlist; } } 
        internal bool   IntegratedSecurity  { get { return _integratedSecurity; } }
        //internal bool   PersistSecurityInfo { get { return _persistSecurityInfo; } }
        internal bool   Pooling             { get { return _pooling; } }
        internal bool   Unicode             { get { return _unicode; } } 
        internal bool   OmitOracleConnectionName  { get { return _omitOracleConnectionName; } }
 
        internal int    LoadBalanceTimeout  { get { return _loadBalanceTimeout; } } 
        internal int    MaxPoolSize         { get { return _maxPoolSize; } }
        internal int    MinPoolSize         { get { return _minPoolSize; } } 

        internal string DataSource          { get { return _dataSource; } }
        internal string UserId              { get { return _userId; } }
        internal string Password            { get { return _password; } } 

        protected internal override System.Security.PermissionSet CreatePermissionSet() { 
            System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None); 
            permissionSet.AddPermission(new OraclePermission(this));
            return permissionSet; 
        }

        // this hashtable is meant to be read-only translation of parsed string
        // keywords/synonyms to a known keyword string 
        internal static Hashtable GetParseSynonyms() {
            const int KeyCount = 12; 
            const int SynonymCount = 7; 

            Hashtable hash = _validKeyNamesAndSynonyms; 
            if (null == hash) {
                hash = new Hashtable(KeyCount + SynonymCount);
                hash.Add(KEY.Data_Source,                   KEY.Data_Source);
                hash.Add(KEY.Enlist,                        KEY.Enlist); 
                hash.Add(KEY.Integrated_Security,           KEY.Integrated_Security);
                hash.Add(KEY.Load_Balance_Timeout,          KEY.Load_Balance_Timeout); 
                hash.Add(KEY.Max_Pool_Size,                 KEY.Max_Pool_Size); 
                hash.Add(KEY.Min_Pool_Size,                 KEY.Min_Pool_Size);
                hash.Add(KEY.OmitOracleConnectionName,      KEY.OmitOracleConnectionName); 
                hash.Add(KEY.Password,                      KEY.Password);
                hash.Add(KEY.Persist_Security_Info,         KEY.Persist_Security_Info);
                hash.Add(KEY.Pooling,                       KEY.Pooling);
                hash.Add(KEY.Unicode,                       KEY.Unicode); 
                hash.Add(KEY.User_ID,                       KEY.User_ID);
 
                hash.Add(SYNONYM.SERVER,                    KEY.Data_Source); 
                hash.Add(SYNONYM.Pwd,                       KEY.Password);
                hash.Add(SYNONYM.PERSISTSECURITYINFO,       KEY.Persist_Security_Info); 
                hash.Add(SYNONYM.UID,                       KEY.User_ID);
                hash.Add(SYNONYM.User,                      KEY.User_ID);
                hash.Add(SYNONYM.Connection_Lifetime,       KEY.Load_Balance_Timeout);
                hash.Add(SYNONYM.WorkaroundOracleBug914652, KEY.OmitOracleConnectionName); 
                Debug.Assert(KeyCount + SynonymCount == hash.Count, "incorrect initial ParseSynonyms size");
                _validKeyNamesAndSynonyms = hash; 
            } 
            return hash;
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK