I am having problems trying to fix this error:
There is already an open DataReader associated with this Command which must be closed first.
I know what this error means and how I should fix it, but I create a new NpgsqlCommand
on an existing NpgsqlConnection
each time and when the previous command is not finished yet, this error occurs.
The command is run as follows:
private object RunSelectScalar(NpgsqlCommand cmd) {
cmd.Connection = connection; // connection is a connected NpgsqlConnection
object result = cmd.ExecuteScalar();
return result;
}
object o = RunSelectScalar(new NpgsqlCommand("SELECT foo FROM bar LIMIT 1"));
so, I don't know how I could close it, or use using
, as I do not assign a DataReader
.
Add
with your connection string. Worked for me.
For example: