SCM

[#1009265] Adapter.Fill with MissingSchemaAction.AddWithKey creates new connection

View Trackers | Bugs | Download .csv | Monitor

Date:
2007-10-01 17:00
Priority:
3
State:
Open
Submitted by:
Andrus Moor (kobruleht)
Assigned to:
Nobody (None)
Npgsql Version:
1.0
Category:
Group:
Resolution:
None
Summary:
Adapter.Fill with MissingSchemaAction.AddWithKey creates new connection

Detailed description
Observed:

Error: Timeout while getting a connection from pool in Fill()

Code to reproduce:

using System.Data;
using Npgsql;
using System.Windows.Forms;

class Program {
static void Main() {
const string s = "ENCODING=UNICODE;SERVER=localhost;DATABASE=postgres;USER=postgres;"
+ ";maxpoolsize=1";

NpgsqlCommand Command = new NpgsqlCommand(
"SELECT * from pg_tables", new NpgsqlConnection(s));

NpgsqlDataAdapter dbAdapter = new NpgsqlDataAdapter(Command);

dbAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
dbAdapter.Fill(new DataSet());
MessageBox.Show("One connection to server is still open");
}
}

Followup

Message
Date: 2008-03-19 11:47
Sender: Jon Hanna

Creating a new connection is entirely appropriate.

The adapter is going to want to obtain a schema table for the resultset it gets from it's select command. It therefore presumably calls GetSchemaTable() on the IDataReader it is using internally (I say "presumably" because Microsoft's implementation of DbDataAdapter is closed-source, if you are using Mono then it's definitely the case, after a quick look at the DbDataAdapter code). GetSchemaTable() will want to contact the database for schema information, and it can't use the connection for the DataReader since the DataReader is still using that, so it uses a clone of that connection.

Perhaps though we should have connections that are only used internally be successfully created even if it causes the MaxPoolSize to be exceeded. I'm not too sure about that either though, since it could hide bugs if such connections were staying alive longer than they should (they are all returned to the pool quickly, but a bug could mean that failed to happen) and then result in a very confusing failure to get a connection somewhere completely unrelated.

In all, I don't think there's any bug, just set MaxPoolSize to something more sensible.

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge