Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Databases
»
Operation cannot be performed on an active dataset
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
[solved] how to get class...
by
Joanna
[
Today
at 12:14:58 pm]
insert select from - with...
by
Nicole
[
Today
at 11:39:34 am]
FpDebug breakpoint on "be...
by
YiannisKam
[
Today
at 11:30:25 am]
Database standards OR Am ...
by
TRon
[
Today
at 11:28:02 am]
Access violation when ope...
by
TRon
[
Today
at 11:24:35 am]
How to: create DLL file f...
by
paule32
[
Today
at 11:17:12 am]
Offical launch of the 1 B...
by
Gustavo 'Gus' Carreno
[
Today
at 11:14:40 am]
Registers dialog - regist...
by
Martin_fr
[
Today
at 11:10:13 am]
Forum slow
by
TRon
[
Today
at 10:57:09 am]
HeapTrc not showing line ...
by
Martin_fr
[
Today
at 10:40:33 am]
Step-into the field sette...
by
ginoo
[
Today
at 07:50:24 am]
Does anyone know why thes...
by
TYDQ
[
Today
at 05:24:32 am]
Arabic text, problem on L...
by
Zaher
[
Today
at 03:29:16 am]
InstallAware Using Lazaru...
by
TRon
[
Today
at 02:55:41 am]
Generics - correct syntax
by
Blaazen
[
Today
at 01:57:40 am]
Demoscene The Champs Crac...
by
Gigatron
[
Today
at 01:05:16 am]
How to use the Event Log?
by
n7800
[
Today
at 12:47:25 am]
v3.99 code completion que...
by
440bx
[
Today
at 12:45:55 am]
Access violation when re-...
by
TRon
[April 19, 2024, 11:44:51 pm]
Lazarus for Windows on aa...
by
Wallaby
[April 19, 2024, 10:52:25 pm]
Poll: Watches and Display...
by
440bx
[April 19, 2024, 07:13:51 pm]
Who is Indy mattias?
by
paweld
[April 19, 2024, 04:17:53 pm]
I just released a commerc...
by
BrassGear
[April 19, 2024, 03:17:28 pm]
A fairly simple sound sol...
by
paweld
[April 19, 2024, 01:46:11 pm]
AI, NLP and CAI: Text Gen...
by
Dzandaa
[April 19, 2024, 11:03:26 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Operation cannot be performed on an active dataset (Read 2868 times)
martinrame
Full Member
Posts: 119
Operation cannot be performed on an active dataset
«
on:
June 22, 2018, 12:29:59 am »
Hi, I'm trying to do a Select, loop through its records, then call a procedure to update each record, but I'm getting "Operation cannot be performed on an active dataset".
I wonder why this error, since my "UpdateRecords" procedure creates a new TSqlQuery instance.
Here's my code:
Code: Pascal
[Select]
[+]
[-]
Procedure
ListRecords
;
var
lSql
:
TSqlQuery
;
id
:
Integer
;
begin
lSql
:
=
TSqlQuery
.
Create
(
nil
)
;
try
lSql
.
DataBase
:
=
DataModule1
.
PQConnection1
;
lSql
.
SQL
.
Text
:
=
'select * from table'
;
lSql
.
Open
;
while
not
lSql
.
Eof
do
begin
id
:
=
lSql
.
FieldByName
(
'id'
)
.
AsInteger
;
UpdateRecord
(
id
)
;
lSql
.
Next
;
end
;
finally
lSql
.
Free
;
end
;
end
;
Procedure
UpdateRecords
(
Id
:
Integer
)
;
var
lSql
:
TSqlQuery
;
begin
lSql
:
=
TSqlQuery
.
Create
(
nil
)
;
try
lSql
.
DataBase
:
=
DataModule1
.
PQConnection1
;
lSql
.
Transaction
:
=
DataModule1
.
SqlTransaction1
;
lSql
.
SQL
.
Text
:
=
'update table set read=true where id=:id'
;
lSql
.
ParamByName
(
'id'
)
.
AsInteger
:
=
id
;
lSql
.
ExecSql
;
DataModule1
.
SqlTransaction1
.
Commit
;
finally
lSql
.
Free
;
end
;
end
;
«
Last Edit: June 22, 2018, 02:06:15 pm by martinrame
»
Logged
valdir.marcos
Hero Member
Posts: 1106
Re: Operation cannI t be performed on an active dataset
«
Reply #1 on:
June 22, 2018, 05:16:10 am »
Why are you slowly updating all that on the client side instead of using the faster server side?
Code: SQL
[Select]
[+]
[-]
UPDATE
TABLE
SET
READ
=
TRUE
WHERE
id
IN
(
SELECT
id
FROM
TABLE
WHERE
condition
=
:condition
)
;
«
Last Edit: June 22, 2018, 05:34:23 am by valdir.marcos
»
Logged
martinrame
Full Member
Posts: 119
Re: Operation cannI t be performed on an active dataset
«
Reply #2 on:
June 22, 2018, 02:01:43 pm »
This is an example, not real code.
Inside my ListRecords function I do many more operations (that cannot be done in the database) than just updating records from the same table.
Logged
martinrame
Full Member
Posts: 119
Re: Operation cannot be performed on an active dataset
«
Reply #3 on:
June 22, 2018, 02:11:03 pm »
Sorry, the error does not comes from this code, but from a nested query I'm doing against an SQLServer Database.
I'll try to isolate it, then come bak.
Logged
martinrame
Full Member
Posts: 119
[SOLVED] Re: Operation cannot be performed on an active dataset
«
Reply #4 on:
June 22, 2018, 02:18:12 pm »
The solution was NOT commiting inside the nested procedure (the one tha does .ExecSQL), but commiting when the main loop ends.
Logged
rvk
Hero Member
Posts: 6163
Re: Operation cannot be performed on an active dataset
«
Reply #5 on:
June 22, 2018, 02:19:59 pm »
My guess is that DataModule1.SqlTransaction1 is also connected to the query in ListRecords (via the database connection in DataModule1). Committing that transaction will also close the query in ListRecords.
You need to re-think the flow or set the correct parameter for the transaction that it will not close the queries automatically. Rethinking the flow is the better choice. Maybe use a separate transaction in UpdateRecords().
Edit: Ah, you already found it
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Databases
»
Operation cannot be performed on an active dataset
TinyPortal
© 2005-2018