public NpgsqlConnection CreateConnection(RoutingInfo routingInfo)
        {
            var cb = new NpgsqlConnectionStringBuilder(connectionString)
            {
                Enlist = true,
                PersistSecurityInfo = true,
            };

            return(new NpgsqlConnection(cb.ToString()));
        }
Пример #2
0
        public NpgsqlConnection CreateConnection(RoutingInfo routingInfo)
        {
            var cb = new NpgsqlConnectionStringBuilder(templateConnString)
            {
                Host   = routingInfo.Host,
                Port   = routingInfo.Port,
                Enlist = true,
                PersistSecurityInfo = true,
            };

            return(new NpgsqlConnection(cb.ToString()));
        }
        private async Task <NpgsqlConnection> GetOrCreateOpenedConnection(RoutingInfo routingInfo)
        {
            var init = StorageInitialization.Current;

            if (connections.TryGetValue(routingInfo.HostAndPort, out NpgsqlConnection connection))
            {
                await init.EnsureStorageIsReadyAsync(connection, schema, routingInfo.Partition).ConfigureAwait(false);

                return(connection);
            }

            connection = connectionFactory.CreateConnection(routingInfo);
            await init.EnsureStorageIsReadyAsync(connection, schema, routingInfo.Partition).ConfigureAwait(false);

            await connection.OpenAsync().ConfigureAwait(false);

            connections.TryAdd(routingInfo.HostAndPort, connection);

            return(connection);
        }