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.
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).
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.
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).
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.
Member
1 Points
11 Posts
DbDataReader gets empty after its reading
May 28, 2015 10:02 AM|MZPERX|LINK
Hi,
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?
EF6 DbDataReader IDbCommandInterceptor
All-Star
184748 Points
26712 Posts
Moderator
MVP
Re: DbDataReader gets empty after its reading
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.
EF6 DbDataReader IDbCommandInterceptor
ASP.NET Tutorials | Learn Entity Framework Core| Learn Razor Pages
All-Star
40130 Points
12984 Posts
Re: DbDataReader gets empty after its reading
May 28, 2015 10:32 AM|PatriceSc|LINK
Hi,
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).
EF6 DbDataReader IDbCommandInterceptor
Member
1 Points
11 Posts
Re: DbDataReader gets empty after its reading
May 28, 2015 10:35 AM|MZPERX|LINK
Thank you.
EF6 DbDataReader IDbCommandInterceptor
Member
1 Points
11 Posts
Re: DbDataReader gets empty after its reading
May 28, 2015 10:41 AM|MZPERX|LINK
Hi,
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.
EF6 DbDataReader IDbCommandInterceptor
All-Star
40130 Points
12984 Posts
Re: DbDataReader gets empty after its reading
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?
EF6 DbDataReader IDbCommandInterceptor
Member
1 Points
11 Posts
Re: DbDataReader gets empty after its reading
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.
Thank you.
EF6 DbDataReader IDbCommandInterceptor