Clone() public méthode

Return an exact copy of this NpgsqlConnectionString.
public Clone ( ) : NpgsqlConnectionStringBuilder
Résultat NpgsqlConnectionStringBuilder
Exemple #1
0
        /// <summary>
        /// This method changes the current database by disconnecting from the actual
        /// database and connecting to the specified.
        /// </summary>
        /// <param name="dbName">The name of the database to use in place of the current database.</param>
        public override void ChangeDatabase(String dbName)
        {
            CheckNotDisposed();

            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "ChangeDatabase", dbName);

            if (dbName == null)
            {
                throw new ArgumentNullException("dbName");
            }

            if (string.IsNullOrEmpty(dbName))
            {
                throw new ArgumentOutOfRangeException("dbName", dbName, String.Format(resman.GetString("Exception_InvalidDbName")));
            }

            String oldDatabaseName = Database;

            Close();

            // Mutating the current `settings` object would invalidate the cached instance, so work on a copy instead.
            settings = settings.Clone();
            settings[Keywords.Database] = dbName;
            _connectionString           = null;

            Open();
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="Npgsql.NpgsqlConnection">NpgsqlConnection</see> class
        /// and sets the <see cref="Npgsql.NpgsqlConnection.ConnectionString">ConnectionString</see>.
        /// </summary>
        /// <param name="ConnectionString">The connection used to open the PostgreSQL database.</param>
        public NpgsqlConnection(String ConnectionString)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME, "NpgsqlConnection()");

            NpgsqlConnectionStringBuilder builder = cache[ConnectionString];

            if (builder == null)
            {
                settings = new NpgsqlConnectionStringBuilder(ConnectionString);
            }
            else
            {
                settings = builder.Clone();
            }

            LogConnectionString();

            NoticeDelegate       = new NoticeEventHandler(OnNotice);
            NotificationDelegate = new NotificationEventHandler(OnNotification);

            ProvideClientCertificatesCallbackDelegate = new ProvideClientCertificatesCallback(DefaultProvideClientCertificatesCallback);

            // Fix authentication problems. See https://bugzilla.novell.com/show_bug.cgi?id=MONO77559 and
            // http://pgfoundry.org/forum/message.php?msg_id=1002377 for more info.
            RSACryptoServiceProvider.UseMachineKeyStore = true;

            promotable = new NpgsqlPromotableSinglePhaseNotification(this);
        }
Exemple #3
0
        /// <summary>
        /// This method changes the current database by disconnecting from the actual
        /// database and connecting to the specified.
        /// </summary>
        /// <param name="dbName">The name of the database to use in place of the current database.</param>
        public override void ChangeDatabase(String dbName)
        {
            CheckNotDisposed();

            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "ChangeDatabase", dbName);

            if (dbName == null)
            {
                throw new ArgumentNullException("dbName");
            }

            if (string.IsNullOrEmpty(dbName))
            {
                throw new ArgumentOutOfRangeException(String.Format(resman.GetString("Exception_InvalidDbName"), dbName), "dbName");
            }

            String oldDatabaseName = Database;

            Close();

            settings = settings.Clone();
            settings[Keywords.Database] = dbName;

            Open();
        }
Exemple #4
0
        private static NpgsqlConnectionStringBuilder GetBuilder(String connectionString)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME, "NpgsqlConnection()");

            NpgsqlConnectionStringBuilder builder = cache[connectionString];

            return(builder == null
                                ? new NpgsqlConnectionStringBuilder(connectionString)
                                : builder.Clone());
        }
Exemple #5
0
        /// <summary>
        /// Sets the `settings` ConnectionStringBuilder based on the given `connectionString`
        /// </summary>
        /// <param name="connectionString">The connection string to load the builder from</param>
        private void LoadConnectionStringBuilder(NpgsqlConnectionStringBuilder connectionString)
        {
            // Clone the settings, because if Integrated Security is enabled, user ID can be different
            settings = connectionString.Clone();

            // Set the UserName explicitly to freeze any Integrated Security-determined names
            if (settings.IntegratedSecurity)
            {
                settings.UserName = settings.UserName;
            }

            RefreshConnectionString();
            LogConnectionString();
        }
        public MultiHostConnectorPool(NpgsqlConnectionStringBuilder settings, string connString) : base(settings, connString)
        {
            var hosts = settings.Host !.Split(',');

            _pools = new ConnectorPool[hosts.Length];
            for (var i = 0; i < hosts.Length; i++)
            {
                var poolSettings = settings.Clone();
                Debug.Assert(!poolSettings.Multiplexing);
                var host = hosts[i].AsSpan().Trim();
                if (NpgsqlConnectionStringBuilder.TrySplitHostPort(host, out var newHost, out var newPort))
                {
                    poolSettings.Host = newHost;
                    poolSettings.Port = newPort;
                }
Exemple #7
0
        /// <summary>
        /// Sets the `settings` ConnectionStringBuilder based on the given `connectionString`
        /// </summary>
        /// <param name="connectionString">The connection string to load the builder from</param>
        void LoadConnectionStringBuilder(NpgsqlConnectionStringBuilder connectionString)
        {
            // Clone the settings, because if Integrated Security is enabled, user ID can be different
            _settings = connectionString.Clone();

            // Set the UserName explicitly to freeze any Integrated Security-determined names
            if (_settings.IntegratedSecurity)
            {
                _settings.UserName = _settings.UserName;
            }

            RefreshConnectionString();

            if (_log.IsTraceEnabled)
            {
                foreach (string key in _settings.Keys)
                {
                    _log.TraceFormat("Connstring dump {0}={1}", key, _settings[key]);
                }
            }
        }
Exemple #8
0
        public MultiHostConnectorPool(NpgsqlConnectionStringBuilder settings, string connString) : base(settings, connString)
        {
            var hosts = settings.Host !.Split(',');

            _pools = new ConnectorPool[hosts.Length];
            for (var i = 0; i < hosts.Length; i++)
            {
                var host          = hosts[i].Trim();
                var port          = settings.Port;
                var portSeparator = host.IndexOf(':');
                if (portSeparator != -1)
                {
                    port = int.Parse(host.Substring(portSeparator + 1));
                    host = host.Substring(0, portSeparator);
                }
                var poolSettings = settings.Clone();
                poolSettings.Host = host;
                poolSettings.Port = port;
                _pools[i]         = new ConnectorPool(poolSettings, poolSettings.ConnectionString, this);
            }
        }
Exemple #9
0
        /// <summary>
        /// Sets the `settings` ConnectionStringBuilder based on the given `connectionString`
        /// </summary>
        /// <param name="connectionString">The connection string to load the builder from</param>
        private void LoadConnectionStringBuilder(NpgsqlConnectionStringBuilder connectionString)
        {
            // Clone the settings, because if Integrated Security is enabled, user ID can be different
            settings = connectionString.Clone();

            // Set the UserName explicitly to freeze any Integrated Security-determined names
            if (settings.IntegratedSecurity)
               settings.UserName = settings.UserName;

            RefreshConnectionString();
            LogConnectionString();
        }
Exemple #10
0
 /// <summary>
 /// Returns a copy of the NpgsqlConnectionStringBuilder that contains the parsed connection string values.
 /// </summary>
 internal NpgsqlConnectionStringBuilder CopyConnectionStringBuilder()
 {
     return(_settings.Clone());
 }
Exemple #11
0
        /// <summary>
        /// Sets the `settings` ConnectionStringBuilder based on the given `connectionString`
        /// </summary>
        /// <param name="connectionString">The connection string to load the builder from</param>
        void LoadConnectionStringBuilder(NpgsqlConnectionStringBuilder connectionString)
        {
            // Clone the settings, because if Integrated Security is enabled, user ID can be different
            _settings = connectionString.Clone();

            // Set the UserName explicitly to freeze any Integrated Security-determined names
            if (_settings.IntegratedSecurity)
                _settings.UserName = _settings.UserName;

            RefreshConnectionString();

            if (_log.IsTraceEnabled)
            {
                foreach (string key in _settings.Keys)
                {
                    _log.TraceFormat("Connstring dump {0}={1}", key, _settings[key]);
                }
            }
        }