Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Database.SqlQuery<T> results Invalid attempt of read when the reader is closed (EF6) [DNET527] #507

Closed
firebird-automations opened this issue Nov 3, 2013 · 6 comments

Comments

@firebird-automations
Copy link

Submitted by: Sergio Cardenas (scardenas)

Votes: 2

This line: MyContext.Database.SqlQuery<MyTableDO>("select * from my_table where id = 1").First(); throws an exception "Invalid attempt of read when the reader is closed". This is working in the provider for EF5 but not in version for EF6

@firebird-automations
Copy link
Author

Commented by: Tobias (tkloss)

I can confirm the bug:
var result = (from x in Context.Table select x).ToList();
works correct, but
var result = Context.Table.SqlQuery("SELECT * FROM TABLE").ToList();
fails with error: "Invalid attempt of read when the reader is closed."
This worked before with EF5.

@firebird-automations
Copy link
Author

Commented by: Tobias (tkloss)

This bug still exists in 4.1.0.0.

I played a bit with the sources. When using SqlQuery, the instance of FbCommand gets disposed before the containing FbDataReader is being accessed. That does not happen with a "normal" Linq-to-SQL query. After modifying the dispose method to not doing anything (just return), the query works correctly. Sure, this is not an acceptable solution, but it could help the experts to identify the underlying problem. I suppose it has something to do with the new async functionality of EF6.

@firebird-automations
Copy link
Author

Modified by: Sergio Cardenas (scardenas)

Version: 4.1.0.0 [ 10583 ]

Component: Entity Framework support [ 10110 ]

Version: 3.2.0.0 [ 10571 ] =>

Component: http://ADO.NET Provider [ 10041 ] =>

@firebird-automations
Copy link
Author

Commented by: Tobias (tkloss)

Bug still exists in 4.5.0.0

The reason could be at this point in ObjectContext.cs of Entity Framework 6, method ExecuteStoreQueryInternal:

using (var command = CreateStoreCommand(commandText, parameters))
{
reader = command.ExecuteReader(...);
}
shaperFactory = InternalTranslate<TElement>(reader, ...);

After the using block, the FbCommand is disposed. Then the reader is accessed.
But in FbCommand, the reader is actively closed if the FbCommand gets disposed.

@firebird-automations
Copy link
Author

Commented by: @cincuranet

As it turns out, this is bug in EF: https://entityframework.codeplex.com/workitem/2418.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants