How to fix “System.InvalidOperationException: Invalid attempt to call Read when reader is closed” when invoking the Compiled QueryInvalid attempt to call Read when reader is closed?Invalid attempt to call Read when reader is closedLinq Query FilterSystem.InvalidOperationException: Invalid attempt to call Read when reader is closedInvalid attempt to call Read when the reader is closedLinq IEnumerable Error which occurs spontaneouslyEntity error with calling Count() after GroupJoinInternal Server Error (MAC OSX) when use dotnet runC# read boolean from databaseNot supported exception with TruncateTime entity framework function
How do you send money when you're not sure it's not a scam?
In this iconic lunar orbit rendezvous photo of John Houbolt, why do arrows #5 and #6 point the "wrong" way?
What is this green alien supposed to be on the American covers of the "Hitchhiker's Guide to the Galaxy"?
Making a Dataset that emulates `ls -tlra`?
Function over a list that depends on the index
Parser for STL stereolithography data files
"Je suis petite, moi?", purpose of the "moi"?
What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?
What would be the safest way to drop thousands of small, hard objects from a typical, high wing, GA airplane?
Last-minute canceled work-trip means I'll lose thousands of dollars on planned vacation
Who is Jambavan an incarnation of?
Equality of complex numbers in general
Are there foods that astronauts are explicitly never allowed to eat?
Is it possible to target 2 allies with the Warding Bond spell using the Sorcerer's Twinned Spell metamagic option?
Discontinuous Tube visualization
How can I help our ranger feel special about her beast companion?
Locked-up DOS computer beeped on keypress. What mechanism caused that?
Company looks for long-term employees, but I know I won't be interested in staying long
Why did my "seldom" get corrected?
Is it possible to have a career in SciComp without contributing to arms research?
Do pedestrians imitate automotive traffic?
Is encryption still applied if you ignore the SSL certificate warning for self-signed certs?
How was Luke's prosthetic hand in Episode V filmed?
When a ball on a rope swings in a circle, is there both centripetal force and tension force?
How to fix “System.InvalidOperationException: Invalid attempt to call Read when reader is closed” when invoking the Compiled Query
Invalid attempt to call Read when reader is closed?Invalid attempt to call Read when reader is closedLinq Query FilterSystem.InvalidOperationException: Invalid attempt to call Read when reader is closedInvalid attempt to call Read when the reader is closedLinq IEnumerable Error which occurs spontaneouslyEntity error with calling Count() after GroupJoinInternal Server Error (MAC OSX) when use dotnet runC# read boolean from databaseNot supported exception with TruncateTime entity framework function
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
When calling ToList() after invoking the compiled query I sometimes(!) receive an exception - System.InvalidOperationException: Invalid attempt to call Read when reader is closed.
The DB context is created for every "invoke" calling, the queries are synchronously compiled before the invocation. The snippet of code is called one time pro file , which are being read asynchronously.
The Query is initialised, compiled and invoked the following way.
public Func<SANAContext, int, string, IEnumerable<KeyValuePair<string, Importartikelhash>>> ImportingArticlesHashesQuery;
...
ImportingArticlesHashesQuery = EF.CompileQuery((SANAContext db, int LaLiNr, string lagerId) => db.Importartikelhash.AsNoTracking()
.Where(la => la.LieferantartikelId == LaLiNr && string.Compare(la.LagerId, lagerId, StringComparison.Ordinal) == 0).Select(a => new KeyValuePair<string, Importartikelhash>(a.LieferartikelNr, a)));
...
List<KeyValuePair<string, Importartikelhash>> records = ImportingArticlesHashesQuery.Invoke(context, supplier.SupplierInternalId, warehouse.Id).ToList();
On a big amount of data i receive an exception :
System.InvalidOperationException: Invalid attempt to call Read when reader is closed.
at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at System.Data.SqlClient.SqlDataReader.Read()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func`3 operation, Func`3 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Sanalogic.SupplierArticlesImport.SupplierDataParserApplication.Services.QueriesCompiler.DBHashValuesCache(PricatSupplier supplier, PricatWarehouse warehouse) in QueriesCompiler.cs:line 90
What can cause the problem? I realize that some problem with asynchrones operations exists, but I don't know where to search for it.
Any help is highly appreciated!
c# ef-core-2.0 compiled-query
add a comment |
When calling ToList() after invoking the compiled query I sometimes(!) receive an exception - System.InvalidOperationException: Invalid attempt to call Read when reader is closed.
The DB context is created for every "invoke" calling, the queries are synchronously compiled before the invocation. The snippet of code is called one time pro file , which are being read asynchronously.
The Query is initialised, compiled and invoked the following way.
public Func<SANAContext, int, string, IEnumerable<KeyValuePair<string, Importartikelhash>>> ImportingArticlesHashesQuery;
...
ImportingArticlesHashesQuery = EF.CompileQuery((SANAContext db, int LaLiNr, string lagerId) => db.Importartikelhash.AsNoTracking()
.Where(la => la.LieferantartikelId == LaLiNr && string.Compare(la.LagerId, lagerId, StringComparison.Ordinal) == 0).Select(a => new KeyValuePair<string, Importartikelhash>(a.LieferartikelNr, a)));
...
List<KeyValuePair<string, Importartikelhash>> records = ImportingArticlesHashesQuery.Invoke(context, supplier.SupplierInternalId, warehouse.Id).ToList();
On a big amount of data i receive an exception :
System.InvalidOperationException: Invalid attempt to call Read when reader is closed.
at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at System.Data.SqlClient.SqlDataReader.Read()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func`3 operation, Func`3 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Sanalogic.SupplierArticlesImport.SupplierDataParserApplication.Services.QueriesCompiler.DBHashValuesCache(PricatSupplier supplier, PricatWarehouse warehouse) in QueriesCompiler.cs:line 90
What can cause the problem? I realize that some problem with asynchrones operations exists, but I don't know where to search for it.
Any help is highly appreciated!
c# ef-core-2.0 compiled-query
add a comment |
When calling ToList() after invoking the compiled query I sometimes(!) receive an exception - System.InvalidOperationException: Invalid attempt to call Read when reader is closed.
The DB context is created for every "invoke" calling, the queries are synchronously compiled before the invocation. The snippet of code is called one time pro file , which are being read asynchronously.
The Query is initialised, compiled and invoked the following way.
public Func<SANAContext, int, string, IEnumerable<KeyValuePair<string, Importartikelhash>>> ImportingArticlesHashesQuery;
...
ImportingArticlesHashesQuery = EF.CompileQuery((SANAContext db, int LaLiNr, string lagerId) => db.Importartikelhash.AsNoTracking()
.Where(la => la.LieferantartikelId == LaLiNr && string.Compare(la.LagerId, lagerId, StringComparison.Ordinal) == 0).Select(a => new KeyValuePair<string, Importartikelhash>(a.LieferartikelNr, a)));
...
List<KeyValuePair<string, Importartikelhash>> records = ImportingArticlesHashesQuery.Invoke(context, supplier.SupplierInternalId, warehouse.Id).ToList();
On a big amount of data i receive an exception :
System.InvalidOperationException: Invalid attempt to call Read when reader is closed.
at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at System.Data.SqlClient.SqlDataReader.Read()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func`3 operation, Func`3 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Sanalogic.SupplierArticlesImport.SupplierDataParserApplication.Services.QueriesCompiler.DBHashValuesCache(PricatSupplier supplier, PricatWarehouse warehouse) in QueriesCompiler.cs:line 90
What can cause the problem? I realize that some problem with asynchrones operations exists, but I don't know where to search for it.
Any help is highly appreciated!
c# ef-core-2.0 compiled-query
When calling ToList() after invoking the compiled query I sometimes(!) receive an exception - System.InvalidOperationException: Invalid attempt to call Read when reader is closed.
The DB context is created for every "invoke" calling, the queries are synchronously compiled before the invocation. The snippet of code is called one time pro file , which are being read asynchronously.
The Query is initialised, compiled and invoked the following way.
public Func<SANAContext, int, string, IEnumerable<KeyValuePair<string, Importartikelhash>>> ImportingArticlesHashesQuery;
...
ImportingArticlesHashesQuery = EF.CompileQuery((SANAContext db, int LaLiNr, string lagerId) => db.Importartikelhash.AsNoTracking()
.Where(la => la.LieferantartikelId == LaLiNr && string.Compare(la.LagerId, lagerId, StringComparison.Ordinal) == 0).Select(a => new KeyValuePair<string, Importartikelhash>(a.LieferartikelNr, a)));
...
List<KeyValuePair<string, Importartikelhash>> records = ImportingArticlesHashesQuery.Invoke(context, supplier.SupplierInternalId, warehouse.Id).ToList();
On a big amount of data i receive an exception :
System.InvalidOperationException: Invalid attempt to call Read when reader is closed.
at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at System.Data.SqlClient.SqlDataReader.Read()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func`3 operation, Func`3 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Sanalogic.SupplierArticlesImport.SupplierDataParserApplication.Services.QueriesCompiler.DBHashValuesCache(PricatSupplier supplier, PricatWarehouse warehouse) in QueriesCompiler.cs:line 90
What can cause the problem? I realize that some problem with asynchrones operations exists, but I don't know where to search for it.
Any help is highly appreciated!
c# ef-core-2.0 compiled-query
c# ef-core-2.0 compiled-query
asked Mar 26 at 10:30
mmammmam
464 bronze badges
464 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Could you please try to increase the command timeout on your context like the following :
public class MyDatabase : DbContext
public MyDatabase ()
: base(ContextHelper.CreateConnection("Connection string"), true)
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;
I also thought about it , but i have already set TimeOut to a pretty big value (500)
– mmam
Mar 26 at 15:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354921%2fhow-to-fix-system-invalidoperationexception-invalid-attempt-to-call-read-when%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Could you please try to increase the command timeout on your context like the following :
public class MyDatabase : DbContext
public MyDatabase ()
: base(ContextHelper.CreateConnection("Connection string"), true)
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;
I also thought about it , but i have already set TimeOut to a pretty big value (500)
– mmam
Mar 26 at 15:03
add a comment |
Could you please try to increase the command timeout on your context like the following :
public class MyDatabase : DbContext
public MyDatabase ()
: base(ContextHelper.CreateConnection("Connection string"), true)
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;
I also thought about it , but i have already set TimeOut to a pretty big value (500)
– mmam
Mar 26 at 15:03
add a comment |
Could you please try to increase the command timeout on your context like the following :
public class MyDatabase : DbContext
public MyDatabase ()
: base(ContextHelper.CreateConnection("Connection string"), true)
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;
Could you please try to increase the command timeout on your context like the following :
public class MyDatabase : DbContext
public MyDatabase ()
: base(ContextHelper.CreateConnection("Connection string"), true)
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;
answered Mar 26 at 11:50
Mahmoud-AbdelslamMahmoud-Abdelslam
1591 silver badge7 bronze badges
1591 silver badge7 bronze badges
I also thought about it , but i have already set TimeOut to a pretty big value (500)
– mmam
Mar 26 at 15:03
add a comment |
I also thought about it , but i have already set TimeOut to a pretty big value (500)
– mmam
Mar 26 at 15:03
I also thought about it , but i have already set TimeOut to a pretty big value (500)
– mmam
Mar 26 at 15:03
I also thought about it , but i have already set TimeOut to a pretty big value (500)
– mmam
Mar 26 at 15:03
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354921%2fhow-to-fix-system-invalidoperationexception-invalid-attempt-to-call-read-when%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown