[Mono-list] Npgsql1.0 Protocol option not supported

Andrus kobruleht2 at hot.ee
Sat Jan 13 18:54:12 EST 2007


Thank you.

My npgsql code works with MONO a week ago but now it suddenly stops working.

It it not possible to set any option which can cause this error.
It is impossible to connect to npgsql now at all, error occurs in first 
connect.
If I ran same exe file directly (it uses .NET 2 framework in this case), all 
is OK.

I looked to the method in npgsql source code which probably causes this
error but haven't found any idea.
How unsupported protocol option can be passed to npgsql/mono/windows ?
How to search for a string "Protocol option not supported" in MONO source
code in internet or must I unpack it to my hard disk?

npgsql Open() method code where this error occurs is:

public override void Open(NpgsqlConnector context)
        {

            try
            {

                NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME,
"Open");

                /*TcpClient tcpc = new TcpClient();
                tcpc.Connect(new IPEndPoint(ResolveIPHost(context.Host),
context.Port));
                Stream stream = tcpc.GetStream();*/

                Socket socket = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);

                /*socket.SetSocketOption (SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, context.ConnectionTimeout*1000);*/

                //socket.Connect(new IPEndPoint(ResolveIPHost(context.Host),
context.Port));

                IAsyncResult result = socket.BeginConnect(new
IPEndPoint(ResolveIPHost(context.Host), context.Port), null, null);

                if
(!result.AsyncWaitHandle.WaitOne(context.ConnectionTimeout*1000, true))
                {
                    socket.Close();
                    throw new
Exception(resman.GetString("Exception_ConnectionTimeout"));
                }

                try
                {
                    socket.EndConnect(result);
                }
                catch (Exception ex)
                {
                    socket.Close();
                    throw;
                }

                Stream stream = new NetworkStream(socket, true);

                // If the PostgreSQL server has SSL connectors enabled Open
SslClientStream if (response == 'S') {
                if (context.SSL || (context.SslMode == SslMode.Require) ||
(context.SslMode == SslMode.Prefer))
                {
                    PGUtil.WriteInt32(stream, 8);
                    PGUtil.WriteInt32(stream,80877103);
                    // Receive response

                    Char response = (Char)stream.ReadByte();
                    if (response == 'S')
                    {
                        stream = new SslClientStream(
                                    stream,
                                    context.Host,
                                    true,
                                    Mono.Security.Protocol.Tls.SecurityProtocolType.Default
                                );

                        ((SslClientStream)stream).ClientCertSelectionDelegate
= new
CertificateSelectionCallback(context.DefaultCertificateSelectionCallback);
                        ((SslClientStream)stream).ServerCertValidationDelegate
= new
CertificateValidationCallback(context.DefaultCertificateValidationCallback);
                        ((SslClientStream)stream).PrivateKeyCertSelectionDelegate
= new
PrivateKeySelectionCallback(context.DefaultPrivateKeySelectionCallback);
                    }
                    else if (context.SslMode == SslMode.Require)
                        throw new
InvalidOperationException(resman.GetString("Exception_Ssl_RequestError"));

                }

                context.Stream = new BufferedStream(stream);
                context.Socket = socket;


                NpgsqlEventLog.LogMsg(resman, "Log_ConnectedTo",
LogLevel.Normal, context.Host, context.Port);
                ChangeState(context, NpgsqlConnectedState.Instance);


            }
            catch (Exception e)
            {
                throw new NpgsqlException(e.Message, e);
            }
        }

    }

}


----- Original Message ----- 
From: "Atsushi Eno" <atsushi at ximian.com>
To: <mono-list at lists.ximian.com>
Sent: Saturday, January 13, 2007 7:14 PM
Subject: Re: [Mono-list] Npgsql1.0 Protocol option not supported


>I don't have any direct answers, but looks like the error message comes
> from our Win32Exception. So, probably there is either some
> misconfiguration (either in yours or mono's) or some kind of mono bug.
> These days I have been able to connect to pgsql successfully on linux.
>
> Atsushi Eno
>
> Andrus wrote:
>> My C# application returns error
>>
>> Protocol option not supported
>>
>> Error occurs in line
>>
>> Connection.Open();
>>
>> Npgsql1.0 source code and docs does not contain such message.
>> When running under .NET 2 this error does not occur.
>>
>> Any idea how to fix it ?
>>
>> Environment:
>>
>> Npgsql1.0
>> MONO 1.2  .net 2 profile
>> monocharge-20070112
>> Windows XP
>> VCS 2005 Express
>>
>> Code where error occurs is:
>>
>> public static void CreateConnection(string Server, string Database,
>>        string User, string Password) {
>>
>> NpgsqlEventLog.Level = LogLevel.Debug;
>> NpgsqlEventLog.LogName = @"c:\NpgsqlLogFile.txt";
>>
>> if (Connection != null)
>>     Connection.Close();
>>
>> ConnectionString = "ENCODING=UNICODE;" +
>>        "SERVER=" + Server + ";" +
>>        "DATABASE=" + Database + ";" +
>>        "USER ID=" + User + ";" +
>>        "PASSWORD=" + Password + ";";
>>
>> Connection = new NpgsqlConnection(ConnectionString);
>> IDbCommand Command = new NpgsqlCommand(@"
>>         SET search_path TO firma1,public;
>>         SELECT sfirmanimi FROM prpalk",
>>      (NpgsqlConnection)Connection);
>> // Follwing line causes error Protocol Option not supported in MONO
>> Connection.Open();
>> }
>>
>> Stack trace:
>>
>> Protocol option not supportedStack trace:   at
>> Npgsql.NpgsqlClosedState.Open
>> (Npgsql.NpgsqlConnector context) [0x00000]
>>   at Npgsql.NpgsqlConnector.Open () [0x00000]
>>   at Npgsql.NpgsqlConnectorPool.GetPooledConnector
>> (Npgsql.NpgsqlConnection
>> Connection) [0x00000]
>>
>>
>> npgsql Log file:
>>
>> 13.01.2007 18:12:45 2364 Debug Entering
>> NpgsqlConnection.NpgsqlConnection(NpgsqlConnection())
>> 13.01.2007 18:12:45 2364 Debug ConnectionString Option: ENCODING =
>> UNICODE
>> 13.01.2007 18:12:45 2364 Debug ConnectionString Option: SERVER =
>> localhost
>> 13.01.2007 18:12:45 2364 Debug ConnectionString Option: DATABASE = mydb
>> 13.01.2007 18:12:45 2364 Debug ConnectionString Option: USER ID = admin
>> 13.01.2007 18:12:45 2364 Debug ConnectionString Option: PASSWORD = p
>> 13.01.2007 18:12:45 2364 Debug Entering NpgsqlCommand.NpgsqlCommand()
>> 13.01.2007 18:12:45 2364 Debug Entering
>> NpgsqlParameterCollection.NpgsqlParameterCollection()
>> 13.01.2007 18:12:45 2364 Debug Set NpgsqlCommand.Transaction =
>> 13.01.2007 18:12:45 2364 Debug Entering NpgsqlConnection.Open()
>> 13.01.2007 18:12:46 2364 Debug Get NpgsqlClosedState.Instance
>> 13.01.2007 18:12:46 2364 Debug Get NpgsqlClosedState.Instance
>> 13.01.2007 18:12:46 2364 Debug Entering NpgsqlClosedState.Open()
>> 13.01.2007 18:12:46 2364 Debug Get NpgsqlClosedState.Instance
>>
>> Andrus.
>>
>> _______________________________________________
>> Mono-list maillist  -  Mono-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>>
>>
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list



More information about the Mono-list mailing list