Last post May 28, 2015 12:17 PM by MZPERX
May 28, 2015 10:02 AM|MZPERX|LINK
I would like to log the EF6 queries with their results with the help of IDbCommandInterceptor.
My problem is the DbDataReader gets empty after I read out all the columns and their values.
How could I preserve the content of the DbDataReader after reading it, please?
May 28, 2015 10:07 AM|Mikesdotnetting|LINK
You should read it into another more persistent container. One option could be a DataTable. Another would be a strongly typed custom container of your own design. DataReaders only support forward-only reading to maximise their efficency.
May 28, 2015 10:32 AM|PatriceSc|LINK
A reader is forward only so this is expected. I noticed Result/OriginalResult that could perhaps help and at worst you would have to keep that handy maybe as a DataTable. Would have to play with that.
But what is your scenario? It seems really overkill and I'm not sure which benefit you could expect from logging data in addition to commands (and what if you read a binary column ?). For example you could perhaps use the context and its .Local property
to see how many entities were loaded (not sure what is your final goal).
May 28, 2015 10:35 AM|MZPERX|LINK
May 28, 2015 10:41 AM|MZPERX|LINK
Unfortunately the application throws meaningless errors and I thought it is due to the messy data in the database, so I try to log the user actions to find the cause of these errors.
I want to see the whole queries because the users do not help me in debugging.
May 28, 2015 10:48 AM|PatriceSc|LINK
Then I would suggest to ask first for help about the exceptions you have. If this is how the application handle exceptions that make them hard to use (for example if you get ex.Message rather than the whole exception chain) then you could review just this
part to start with. Finally logging just the query could be enough. For now it really seems you try to log too much and too early in your debug process (and maybe will see such details were not needed at all).
What kind of exceptions do you have?
May 28, 2015 12:17 PM|MZPERX|LINK
The real problem, in my opinion that my customer did not want to clear the data before the migration and Ialso get a lot of errors due to the slow network, I think. They say 'the site has broken', or 'I have an error'. The app logs the unhandled errors,
but I would need the exact environment of them. You are right I do not need the results of the queries and I think over th necessary data to log.