実行中のリーダーを停止することは可能ですか?
シナリオ: 100000 個のデータ セットを含むテーブルがあります
CREATE TABLE stock (
uid bigint NOT NULL,
name text,
quantity integer,
x bytea,
y bytea
);
およびデータを読み取るためのコンソール アプリケーション (.NET 4.0、Npgsql 2.0.11.0/2.0.11.92)
conn = new NpgsqlConnection("Server=localhost;Database=postgres;User id=postgres;password=postgres;Timeout=600;CommandTimeout=600;ConnectionLifeTime=600;");
using (new ConnectionOpen(conn))
using (var ta = conn.BeginTransaction(IsolationLevel.Snapshot))
{
IDbCommand command = conn.CreateCommand("SELECT * from stock;");
command.SetTransaction(ta);
IDataReader reader = command.ExecuteReader();
int n = 0;
while (!reader.IsClosed && reader.Read())
{
n++;
if (n > 5000)
{
if (reader != null)
{
((NpgsqlDataReader)reader).Close();
}
}
}
((NpgsqlDataReader)reader).Dispose();
reader = null;
}
データ リーダーが実際に停止できないことを確認しました。データリーダーは最初にすべての行を読み取り、その後正常に戻るようです。
この例は、読み取りに時間がかかりすぎるためにユーザーがボタンを押してデータ リーダーを停止する、より大きなアプリケーションの要約です。