diff --git a/packages/fcl-db/src/sqldb/sqldb.pp b/packages/fcl-db/src/sqldb/sqldb.pp index 4899246071..c8ff3f31c8 100644 --- a/packages/fcl-db/src/sqldb/sqldb.pp +++ b/packages/fcl-db/src/sqldb/sqldb.pp @@ -2518,13 +2518,21 @@ Const var Q : TSQLQuery; + C : TSQLConnection; begin Q:=DS as TSQLQuery; if not (sqoKeepOpenOnCommit in Q.Options) then inherited CloseDataset(Q,InCommit); - if UnPrepOptions[InCommit] in SQLConnection.ConnOptions then - Q.UnPrepare; + C:=SQLConnection; + if C=Nil then + C:=Q.SQLConnection; + if Q.Prepared then + if not Assigned(C) then + // No database, we must unprepare... + Q.UnPrepare // Unprepare checks if there is still a cursor. + else if UnPrepOptions[InCommit] in C.ConnOptions then + Q.UnPrepare; end; procedure TSQLTransaction.Commit;