Skip to content

An exception occurred while iterating over the results of a query for context type 'DatabaseContext'. System.ArgumentOutOfRangeException: operation=0 #963

Description

@oshinyil

Hi,

I got issue when using FirebirdSql.EntityFrameworkCore.Firebird version 7.10.1. This issue does not always happen and I don't know how the exact step reproduce it. This happened few times in production.

An exception occurred while iterating over the results of a query for context type 'HP.Database.HpDatabaseContext'.
System.ArgumentOutOfRangeException: operation=0
Parameter name: operation
   at FirebirdSql.Data.Client.Managed.GdsConnection.ProcessOperation(Int32 operation, IXdrReader xdr)
   at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadSingleResponse(Int32 operation)
   at FirebirdSql.Data.Client.Managed.Version11.GdsDatabase.ProcessDeferredPackets()
   at FirebirdSql.Data.Client.Managed.Version11.GdsDatabase.ReadOperation()
   at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse[TResponse]()
   at FirebirdSql.Data.Client.Managed.Version10.GdsTransaction.BeginTransaction(TransactionParameterBuffer tpb)
   at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.BeginTransaction(TransactionParameterBuffer tpb)
   at FirebirdSql.Data.FirebirdClient.FbTransaction.BeginTransaction()
   at FirebirdSql.Data.FirebirdClient.FbCommand.Prepare(Boolean returnsSet)
   at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteCommand(CommandBehavior behavior, Boolean returnsSet)
   at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.<InitializeReaderAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.<MoveNextAsync>d__17.MoveNext() 

Here is the translated query.

Failed executing DbCommand (0ms) [Parameters=[@__printerAddress_0='?' (Size = 33)], CommandType='Text', CommandTimeout='30']
SELECT "t7"."TerminalId", "t7"."ActiveGuiSessionId", "t7"."Discriminator", "t7"."Enabled", "t7"."UiContextId", "t7"."Certificate", "t7"."CurrentMode", "t7"."PendingMode", "t7"."TerminalId0", "t7"."Core_AdminPassword", "t7"."Core_AdminPin", "t7"."Core_AdminUsername", "t7"."Core_DefaultLoginMethodDisplay", "t7"."Core_FaxModule", "t7"."Core_GuestLogin", "t7"."Core_GuestLoginScreen", "t7"."Core_IdleTimeout", "t7"."Core_LoginMethod", "t7"."Core_LoginMethodSimple", "t7"."Core_Model", "t7"."Core_PackageUrl", "t7"."Core_PrinterAddress", "t7"."Core_PrinterId", "t7"."Core_SerialNumber", "t7"."TerminalId1", "t7"."Core_SmtpInfo_Address", "t7"."Core_SmtpInfo_Port", "t7"."Core_SmtpInfo_SenderAddress", "t7"."Id", "t7"."AccountSessionReference", "t7"."AccountSessionSessionId", "t7"."Discriminator0", "t7"."EndTime", "t7"."MachineId", "t7"."ModelSrc", "t7"."SelectedProject", "t7"."StartTime", "t7"."TerminalId2", "t7"."Id0", "t7"."User_Domain", "t7"."User_Email", "t7"."User_FullName", "t7"."User_Id", "t7"."User_UserName", "t7"."Reference", "t7"."SessionId", "t7"."Discriminator1", "t7"."GroupId", "t7"."InitialSessionId", "t7"."IsClosed", "t7"."PriceListSrc", "t7"."TerminalId3", "t7"."TerminalIpAddress", "t7"."Username", "t7"."AvailableBalance", "t7"."UnblockedBalance", "t7"."ExclusiveOwnership", "t7"."Rules", "t8"."Id", "t8"."AccountSessionReference", "t8"."AccountSessionSessionId", "t8"."Commited", "t8"."Discriminator", "t8"."JobId", "t8"."BlockedAmount", "t8"."PaidAmount", "t8"."BlockedCountersData"
FROM (
    SELECT "t"."TerminalId", "t"."ActiveGuiSessionId", "t"."Discriminator", "t"."Enabled", "t"."UiContextId", "t"."Certificate", "t"."CurrentMode", "t"."PendingMode", "t1"."TerminalId" AS "TerminalId0", "t1"."Core_AdminPassword", "t1"."Core_AdminPin", "t1"."Core_AdminUsername", "t1"."Core_DefaultLoginMethodDisplay", "t1"."Core_FaxModule", "t1"."Core_GuestLogin", "t1"."Core_GuestLoginScreen", "t1"."Core_IdleTimeout", "t1"."Core_LoginMethod", "t1"."Core_LoginMethodSimple", "t1"."Core_Model", "t1"."Core_PackageUrl", "t1"."Core_PrinterAddress", "t1"."Core_PrinterId", "t1"."Core_SerialNumber", "t5"."TerminalId" AS "TerminalId1", "t5"."Core_SmtpInfo_Address", "t5"."Core_SmtpInfo_Port", "t5"."Core_SmtpInfo_SenderAddress", "t2"."Id", "t2"."AccountSessionReference", "t2"."AccountSessionSessionId", "t2"."Discriminator" AS "Discriminator0", "t2"."EndTime", "t2"."MachineId", "t2"."ModelSrc", "t2"."SelectedProject", "t2"."StartTime", "t2"."TerminalId" AS "TerminalId2", "t6"."Id" AS "Id0", "t6"."User_Domain", "t6"."User_Email", "t6"."User_FullName", "t6"."User_Id", "t6"."User_UserName", "t3"."Reference", "t3"."SessionId", "t3"."Discriminator" AS "Discriminator1", "t3"."GroupId", "t3"."InitialSessionId", "t3"."IsClosed", "t3"."PriceListSrc", "t3"."TerminalId" AS "TerminalId3", "t3"."TerminalIpAddress", "t3"."Username", "t3"."AvailableBalance", "t3"."UnblockedBalance", "t3"."ExclusiveOwnership", "t3"."Rules"
    FROM "Terminals" AS "t"
    LEFT JOIN (
        SELECT "t0"."TerminalId", "t0"."Core_AdminPassword", "t0"."Core_AdminPin", "t0"."Core_AdminUsername", "t0"."Core_DefaultLoginMethodDisplay", "t0"."Core_FaxModule", "t0"."Core_GuestLogin", "t0"."Core_GuestLoginScreen", "t0"."Core_IdleTimeout", "t0"."Core_LoginMethod", "t0"."Core_LoginMethodSimple", "t0"."Core_Model", "t0"."Core_PackageUrl", "t0"."Core_PrinterAddress", "t0"."Core_PrinterId", "t0"."Core_SerialNumber"
        FROM "Terminals" AS "t0"
        WHERE "t0"."Core_PrinterId" IS NOT NULL AND ("t0"."Core_LoginMethodSimple" IS NOT NULL AND ("t0"."Core_LoginMethod" IS NOT NULL AND ("t0"."Core_IdleTimeout" IS NOT NULL AND ("t0"."Core_FaxModule" IS NOT NULL AND "t0"."Core_DefaultLoginMethodDisplay" IS NOT NULL))))
    ) AS "t1" ON "t"."TerminalId" = "t1"."TerminalId"
    LEFT JOIN (
        SELECT "s"."Id", "s"."AccountSessionReference", "s"."AccountSessionSessionId", "s"."Discriminator", "s"."EndTime", "s"."MachineId", "s"."ModelSrc", "s"."SelectedProject", "s"."StartTime", "s"."TerminalId"
        FROM "Sessions" AS "s"
        WHERE "s"."Discriminator" IN (CAST(_UTF8'GuiSession' AS VARCHAR(10) CHARACTER SET UTF8), CAST(_UTF8'HpGuiSession' AS VARCHAR(12) CHARACTER SET UTF8))
    ) AS "t2" ON "t"."ActiveGuiSessionId" = "t2"."Id"
    LEFT JOIN (
        SELECT "a"."Reference", "a"."SessionId", "a"."Discriminator", "a"."GroupId", "a"."InitialSessionId", "a"."IsClosed", "a"."PriceListSrc", "a"."TerminalId", "a"."TerminalIpAddress", "a"."Username", "a"."AvailableBalance", "a"."UnblockedBalance", "a"."ExclusiveOwnership", "a"."Rules"
        FROM "AccountSessions" AS "a"
        WHERE "a"."Discriminator" IN (CAST(_UTF8'CostCenterAccountSession' AS VARCHAR(24) CHARACTER SET UTF8), CAST(_UTF8'CreditAccountSession' AS VARCHAR(20) CHARACTER SET UTF8), CAST(_UTF8'NoAccountSession' AS VARCHAR(16) CHARACTER SET UTF8), CAST(_UTF8'QuotaAccountSession' AS VARCHAR(19) CHARACTER SET UTF8))
    ) AS "t3" ON ("t2"."AccountSessionReference" = "t3"."Reference") AND ("t2"."AccountSessionSessionId" = "t3"."SessionId")
    LEFT JOIN (
        SELECT "t4"."TerminalId", "t4"."Core_SmtpInfo_Address", "t4"."Core_SmtpInfo_Port", "t4"."Core_SmtpInfo_SenderAddress"
        FROM "Terminals" AS "t4"
        WHERE "t4"."Core_SmtpInfo_SenderAddress" IS NOT NULL OR ("t4"."Core_SmtpInfo_Port" IS NOT NULL OR "t4"."Core_SmtpInfo_Address" IS NOT NULL)
    ) AS "t5" ON "t1"."TerminalId" = "t5"."TerminalId"
    LEFT JOIN (
        SELECT "s0"."Id", "s0"."User_Domain", "s0"."User_Email", "s0"."User_FullName", "s0"."User_Id", "s0"."User_UserName"
        FROM "Sessions" AS "s0"
        WHERE "s0"."User_Id" IS NOT NULL
    ) AS "t6" ON "t2"."Id" = "t6"."Id"
    WHERE ("t"."Discriminator" = CAST(_UTF8'HpTerminal' AS VARCHAR(10) CHARACTER SET UTF8)) AND ("t"."Enabled" AND ("t1"."Core_PrinterAddress" = CAST(@__printerAddress_0 AS VARCHAR(8191))))
    ROWS (2)
) AS "t7"
LEFT JOIN (
    SELECT "a0"."Id", "a0"."AccountSessionReference", "a0"."AccountSessionSessionId", "a0"."Commited", "a0"."Discriminator", "a0"."JobId", "a0"."BlockedAmount", "a0"."PaidAmount", "a0"."BlockedCountersData"
    FROM "Allocations" AS "a0"
    WHERE "a0"."Discriminator" IN (CAST(_UTF8'CreditAllocation' AS VARCHAR(16) CHARACTER SET UTF8), CAST(_UTF8'NoAllocation' AS VARCHAR(12) CHARACTER SET UTF8), CAST(_UTF8'QuotaAllocation' AS VARCHAR(15) CHARACTER SET UTF8))
) AS "t8" ON (("t7"."Reference" = "t8"."AccountSessionReference") OR ("t7"."Reference" IS NULL AND "t8"."AccountSessionReference" IS NULL)) AND (("t7"."SessionId" = "t8"."AccountSessionSessionId") OR ("t7"."SessionId" IS NULL AND "t8"."AccountSessionSessionId" IS NULL))
ORDER BY "t7"."TerminalId", "t8"."Id" 

And here is the LINQ

DatabaseContext
     .Terminals
     .Include(t => t.ActiveGuiSession)
     .ThenInclude(s => s.AccountSession)
     .ThenInclude(a => a.Allocations)
     .SingleOrDefaultAsync(t => t.Enabled && t.Core.PrinterAddress == printerAddress);

Please help to fix this issue.

Thank you.

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions