简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM