开发者

DataReader within a DataReader

开发者 https://www.devze.com 2023-04-01 21:57 出处:网络
I have a DataReader...I use the result of the DataReader as开发者_Go百科 parameter on another DataReader that is connected to a command with a Stored Procedure type. It works fast for now but I worry

I have a DataReader...I use the result of the DataReader as开发者_Go百科 parameter on another DataReader that is connected to a command with a Stored Procedure type. It works fast for now but I worry about the time when my database is filled with information. How can I speed things up? Thanks


Likely, your initial query could stand to join to the results generated by the sproc.


Essentially, you have 2 database round-trips instead of one. This may be a performance problem if you call this frequently and the result is small and you have already optimized both query and the stored procedure (so the round-trip overhead becomes significant relative to the actual useful work).

Benchmark and see if this piece of functionality is actually a bottleneck. If yes, you may try to "merge" these two operations at the SQL level, so they can be executed server-size in one go.

I'm not sure if this is related to your question, but keep in mind that (depending on your DBMS / ADO.NET provider), multiple active readers on the same connection may or may not be supported. Are you closing the first DbDataReader before opening the second one? If no, and you happen to switch to a different DBMS, there may be trouble. If memory serves me well, Oracle (ODP.NET) and DB2 support multiple readers, while MS SQL Server and PostgreSQL (Npgsql) don't.

0

精彩评论

暂无评论...
验证码 换一张
取 消