Example #1
0
        public override void Startup(NpgsqlConnector context, NpgsqlConnectionStringBuilder settings)
        {
            NpgsqlStartupPacket startupPacket = new NpgsqlStartupPacket(context.Database, context.UserName, settings);

            startupPacket.WriteToStream(context.Stream);
            context.RequireReadyForQuery = false;

            ProcessAndDiscardBackendResponses(context);
        }
Example #2
0
        public override void Startup(NpgsqlConnector context,NpgsqlConnectionStringBuilder settings)
        {
            NpgsqlStartupPacket startupPacket = new NpgsqlStartupPacket(context.Database, context.UserName, settings);

            startupPacket.WriteToStream(context.Stream);
            context.RequireReadyForQuery = false;

            ProcessAndDiscardBackendResponses(context);
        }
Example #3
0
        public override void Startup(NpgsqlConnector context, NpgsqlConnectionStringBuilder settings)
        {
            NpgsqlStartupPacket startupPacket = NpgsqlStartupPacket.BuildStartupPacket(context.BackendProtocolVersion,
                                                                                       context.Database, context.UserName, settings);

            startupPacket.WriteToStream(context.Stream);
            context.RequireReadyForQuery = false;
            // This still makes part of the connection stablishment handling.
            // So we use the connectiontimeout here too.
            context.Mediator.CommandTimeout = context.ConnectionTimeout;
            ProcessAndDiscardBackendResponses(context);
        }
Example #4
0
        public override void Startup(NpgsqlConnector context)
        {
            NpgsqlStartupPacket startupPacket = new NpgsqlStartupPacket(296, //Not used.
                                                                        context.BackendProtocolVersion, context.Database,
                                                                        context.UserName, "", "", "");

            startupPacket.WriteToStream(new BufferedStream(context.Stream));
            context.RequireReadyForQuery = false;
            // This still makes part of the connection stablishment handling.
            // So we use the connectiontimeout here too.
            context.Mediator.CommandTimeout = context.ConnectionTimeout;
            context.Stream.Flush();
            ProcessBackendResponses(context);
        }
        public override void Startup(NpgsqlConnector context)
        {
            NpgsqlStartupPacket startupPacket = new NpgsqlStartupPacket(296,             //Not used.
                                                                        context.BackendProtocolVersion, context.Database,
                                                                        context.UserName, "", "", "");

            startupPacket.WriteToStream(new BufferedStream(context.Stream));
            context.RequireReadyForQuery = false;
            // This still makes part of the connection stablishment handling.
            // So we use the connectiontimeout here too.
            context.Mediator.CommandTimeout = context.ConnectionTimeout;
            context.Stream.Flush();
            ProcessBackendResponses(context);
        }
        public override void Startup(NpgsqlConnector context)
        {
            NpgsqlStartupPacket startupPacket  = new NpgsqlStartupPacket(296, //Not used.
                                                  context.BackendProtocolVersion,
                                                  context.Database,
                                                  context.UserName,
                                                  "",
                                                  "",
                                                  "");

            startupPacket.WriteToStream( new BufferedStream(context.Stream), context.Encoding );
            context.Mediator.RequireReadyForQuery = false;
            ProcessBackendResponses( context );
        }
        public override void Startup(NpgsqlConnector context)
        {
            NpgsqlStartupPacket startupPacket = new NpgsqlStartupPacket(296, //Not used.
                                                                        context.BackendProtocolVersion,
                                                                        context.Database,
                                                                        context.UserName,
                                                                        "",
                                                                        "",
                                                                        "");

            startupPacket.WriteToStream(new BufferedStream(context.Stream), context.Encoding);
            context.Mediator.RequireReadyForQuery = false;
            context.Mediator.CommandTimeout       = 20;
            context.Stream.Flush();
            ProcessBackendResponses(context);
        }
Example #8
0
        /// <summary>
        /// Opens the physical connection to the server.
        /// </summary>
        /// <remarks>Usually called by the RequestConnector
        /// Method of the connection pool manager.</remarks>
        internal void Open()
        {
            if (State != NpgsqlState.Closed) {
                throw new InvalidOperationException("Can't open, state is " + State);
            }

            State = NpgsqlState.Connecting;

            ServerVersion = null;

            // Keep track of time remaining; Even though there may be multiple timeout-able calls,
            // this allows us to still respect the caller's timeout expectation.
            var connectTimeRemaining = ConnectionTimeout * 1000;

            // Get a raw connection, possibly SSL...
            RawOpen(connectTimeRemaining);
            try
            {
                // Establish protocol communication and handle authentication...
                var startupPacket = new NpgsqlStartupPacket(Database, UserName, _settings);
                startupPacket.WriteToStream(Stream);
                ProcessAndDiscardBackendResponses();
            }
            catch
            {
                if (Stream != null)
                {
                    try {
                        Stream.Dispose();
                    }
                    catch {}
                }

                throw;
            }

            // Change the state of connection to open and ready.
            State = NpgsqlState.Ready;

            // After attachment, the stream will close the connector (this) when the stream gets disposed.
            BaseStream.AttachConnector(this);

            // Fall back to the old way, SELECT VERSION().
            // This should not happen for protocol version 3+.
            if (ServerVersion == null)
            {
                //NpgsqlCommand command = new NpgsqlCommand("set DATESTYLE TO ISO;select version();", this);
                //ServerVersion = new Version(PGUtil.ExtractServerVersion((string) command.ExecuteScalar()));
                using (var command = new NpgsqlCommand("set DATESTYLE TO ISO;select version();", this))
                {
                    ServerVersion = new Version(PGUtil.ExtractServerVersion((string)command.ExecuteScalar()));
                }
            }

            ProcessServerVersion();

            var sbInitQueries = new StringWriter();

            // Some connection parameters for protocol 3 had been sent in the startup packet.
            // The rest will be setted here.
            sbInitQueries.WriteLine("SET extra_float_digits=3;");
            sbInitQueries.WriteLine("SET ssl_renegotiation_limit=0;");

            _initQueries = sbInitQueries.ToString();

            ExecuteBlind(_initQueries);

            // Make a shallow copy of the type mapping that the connector will own.
            // It is possible that the connector may add types to its private
            // mapping that will not be valid to another connector, even
            // if connected to the same backend version.
            NativeToBackendTypeConverterOptions.OidToNameMapping = NpgsqlTypesHelper.CreateAndLoadInitialTypesMapping(this).Clone();

            // The connector is now fully initialized. Beyond this point, it is
            // safe to release it back to the pool rather than closing it.
            IsInitialized = true;
        }