Kuba Matjanowski
Kuba Matjanowski

Reputation: 350

Re-using DataReader for another connection

My task is to save the state of DataReader for another connection to the same base.

I have got many tables in my database. One of them is always read-only, another are allowed to modify. I would like to create DataReader which will be re-open on recent position after opening the same connection. I need to modify other tables in way depending on read-only table content and every time my searching would be start from recent row.

My read-only table is really big and using DataReader makes my program much incomparably faster. I'm looking for solutions for SQL Server, DAO and Oracle.

EDIT: In fact it could be still the same connection, but I need to read and write to different tables alternately.

Upvotes: 1

Views: 172

Answers (1)

smiling4ever
smiling4ever

Reputation: 152

As long as the connection is open and the datareader did not reach the last row of the executed query, the DataReader.Read() will fetch the next row. But when the connection closes, the underlying datareader will be closed as well, hence, you will need to execute the query again, and you will start the iteration on row 1.

One possible method to achieve your need is to create a boolean field in your table that indicates the cursor position. Then adjust your query to start with the row that has this field set to true.

Upvotes: 1

Related Questions