[Mono-devel-list] Npgsql possible bug

yoros at wanadoo.es yoros at wanadoo.es
Fri Dec 26 09:59:35 EST 2003


On Fri, Dec 26, 2003 at 01:17:45PM +0100, Jaroslaw Kowalski wrote:
> > Yes, that code shouldn't be there but when we use NpgsqlDataAdapter with
> > DataSet, DataTable, etc... the connection is not closed:
> >
> > LOG:  pq_recvbuf: unexpected EOF on client connection
> >
> > I think that when a command is disposed, it's underlying connection
> > shouldn't be disposed too but the physical connection can be closed and
> > the connection changes its inner state. In this way the connection can
> > be reopenend...
> 
> I'm not sure about that. I think that the only semantics
> IDbCommand.Dispose() has is: "release any database resources related to the
> command (un-prepare it)". In general there can be open transactions or an
> open datareader, so you cannot close the database connection.
> 
> In some book I've seen a pattern like:
> 
> using (IDbConnection c = ...)
> {
>     IDbTransaction tran = c.BeginTransaction();
> 
>     using (IDbCommand cmd = c.CreateCommand())
>     {
>         cmd.Transaction = tran;
>         using (IDataReader reader = cmd.ExecuteReader())
>         {
>         }
>     }
>     using (IDbCommand cmd = c.CreateCommand())
>     {
>         cmd.Transaction = tran;
>         using (IDataReader reader = cmd.ExecuteReader())
>         {
>         }
>     }
>     tran.Close();
> }
> 
> This would obviously fail with IDbCommand.Dispose() calling
> IDbConnection.Dispose().
> 
> P.S. If you want to make sure the connection gets closed after the whole
> IDataReader has been processed you should use
> "CommandBehavior.CloseConnection" on ExecuteReader(). This is implemented in
> NpgsqlDataReader.
> 

Ok, then the NpgsqlDataAdapter or DbDataAdapter should be modified to
close the connection when Disposed is called. I don't know if this is
right, but there should be any way to close the connection when using
DataAdapters...

See you,

    Pedro

-- 
Pedro Martínez Juliá
\  yoros at terra.es
)|    yoros at wanadoo.es
/        http://yoros.dyndns.org
Socio HispaLinux #311
Usuario Linux #275438 - http://counter.li.org
GnuPG public information:  pub  1024D/74F1D3AC
Key fingerprint = 8431 7B47 D2B4 5A46 5F8E  534F 588B E285 74F1 D3AC



More information about the Mono-devel-list mailing list