I\'m having a lot of trouble with the OracleDataReader in ODP.Net. Basically, I have a parameterized query that takes anywhere from 1-5 seconds to run (returning around 450 rec
May be I am wrong, but you actually fetch the data in this row: While dr.Read
, and not when you are executing the reader. So this can explain why even without doing nothing, dr.Read
take all your time.
I'd try to change your command to
1). Run plain sql (without parameters)
2). Run using regular (not binding variable) parameter
3). Move the sql code to Stored Procedure if possible
Work with your DBAs and ask them to capture an explain plan for both the stand alone run (aqua data studio) and your odp.net call and confirm they are in fact the same. If they are not, then that will probably explain your problem. You can then try adding "enlist=false" to your connection string but better yet have the DBA's update the statistics on the related tables, hopefully fixing the slow plan. See https://stackoverflow.com/a/14712992/852208 for more info.
I have had this same issue and it came down to oracle being less optimistic about the execution plan when a distributed transaction could be involved.