I also do not use PostgreSQL, but to do a fetch on a second command you need to call conn.BeginTransaction(), to turn off implicit commits, so the cursor stays open. also you can just use the same command.
var tran = postcon.BeginTransaction();
using (var command = new NpgsqlCommand(sqlstr, postcon))
{
command.ExecuteNonQuery(); // Execute the DO block to set up the cursor
command.Text = "FETCH ALL FROM p_tenant_cur;";
command.CommandType = CommandType.Text;
using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(command))
{
adapter.TableMappings.Add("Table1", "p_tenant_cur");
adapter.Fill(ds);
}
}
tran.Commit();
response.ds = ds;
not sure how your connection (postcon) get created, but it should have a using statement.