Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

System.InvalidOperationException: Invalid operation. The connection is closed

$
0
0

I've got a Server Side Blazor.NET Application that load data from a Database when a page load or when clicking on the filter button after selecting two dates.When some data is loaded and displayed and I reload the page, I get an error System.InvalidOperationException: Invalid operation. The connection is closed.

Here is the code for the service that's failing with an error

namespace PlanificationFineARS.Services{    public class OFService : IOFService    {        private readonly PlanificationFineARSContext _context;        public OFService(PlanificationFineARSContext context) {            _context = context;        }        public Task<List<OF>> GetAllOFsInPochette(DateOnly startDate, DateOnly endDate)        {            return _context.OF.Where(of => of.pochette != null && of.datePrevision >= startDate && of.datePrevision <= endDate).OrderBy(of => of.datePrevision).Include(of => of.pochette).ToListAsync();        }    }}

Here is the code for the page calling the service

protected TableMachine OFsTab1;protected TableMachine OFsTab2;protected TableMachine OFsTab3;    //...protected override async Task OnInitializedAsync(){    await base.OnInitializedAsync();    LoadInitialData();}protected async void LoadInitialData(){    DateTime baseDate = DateTime.Today;    startDateTime = baseDate.AddDays(-(int)baseDate.DayOfWeek);    endDateTime = startDateTime.AddDays(7).AddSeconds(-1);    startDate = DateOnly.FromDateTime(startDateTime);    endDate = DateOnly.FromDateTime(endDateTime);    await makeFullOFsList(startDate, endDate);    this.StateHasChanged();    OFsTab1.RefreshMe();    OFsTab2.RefreshMe();    OFsTab3.RefreshMe();}protected async Task makeFullOFsList(DateOnly startDate, DateOnly endDate){    isLoading = true;    List<OF> AllOFs = new List<OF>();    try    {        AllOFs = await OFService.GetAllOFsInPochette(startDate, endDate);    } catch (System.InvalidOperationException ioe)    {        Console.WriteLine(ioe);    }    //...}

Here is the full error:

fail: Microsoft.EntityFrameworkCore.Database.Command[20102]      Failed executing DbCommand (21ms) [Parameters=[@__startDate_0='?' (DbType = Date), @__endDate_1='?' (DbType = Date)], CommandType='Text', CommandTimeout='30']      SELECT [o].[Id], [o].[clientName], [o].[comment], [o].[dateExpedition], [o].[dateFabrication], [o].[datePrevision], [o].[designation], [o].[diameter], [o].[machine], [o].[mandrin], [o].[nCommande], [o].[nOF], [o].[numero], [o].[pochetteId], [o].[productionTime], [o].[quantity], [o].[timeTH], [o].[totalWidth], [o].[width], [p].[Id], [p].[machine], [p].[nPochetteText], [p].[timeTotal], [p].[totalWidth]      FROM [OF] AS [o]      LEFT JOIN [Pochette] AS [p] ON [o].[pochetteId] = [p].[Id]      WHERE [p].[Id] IS NOT NULL AND [o].[datePrevision] >= @__startDate_0 AND [o].[datePrevision] <= @__endDate_1      ORDER BY [o].[datePrevision]fail: Microsoft.EntityFrameworkCore.Query[10100]      An exception occurred while iterating over the results of a query for context type 'PlanificationFineARS.Data.PlanificationFineARSContext'.      System.InvalidOperationException: Invalid operation. The connection is closed.         at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__211_0(Task`1 result)         at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)      --- End of stack trace from previous location ---         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)      --- End of stack trace from previous location ---         at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)         at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)         at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)         at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)         at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()      System.InvalidOperationException: Invalid operation. The connection is closed.         at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__211_0(Task`1 result)         at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)      --- End of stack trace from previous location ---         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)      --- End of stack trace from previous location ---         at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)         at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)         at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)         at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)         at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()System.InvalidOperationException: Invalid operation. The connection is closed.   at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__211_0(Task`1 result)   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)--- End of stack trace from previous location ---   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)--- End of stack trace from previous location ---   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)   at PlanificationFineARS.Components.Pages.OFPages.FeuilleAffichageOFs.makeFullOFsList(DateOnly startDate, DateOnly endDate) in C:\Users\g.breton\source\repos\PlanificationFineARS\Components\Pages\OFPages\FeuilleAffichageOFs.razor:line 113

If anyone knows what is causing the issue, please let me know.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>