Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-06

SQLTransaction: Operation cannot be performed on an active transaction

8 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Eric Kom
Good day all;

I am trying to set the Active property of TSQLTransaction to False so that I can avoid the above Read Error message:
SQLTransaction: Operation cannot be performed on an active transaction The True value is currently set to True.

Kind Regards Eric Kom System Administrator & Programmer - Metropolitan College _________________________________________ / You are scrupulously honest, frank, and \ | straightforward. Therefore you have few | \ friends. / ----------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| Kom | ) /'\_ _/`\ \___)=(___/ 2 Hennie Van Till, White River, 1240 Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334 | www.kom.za.net | www.kom.za.org | www.erickom.co.za Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5

Reply by email

Antonio Fortuny
to Eric Kom

Le 04/06/2013 09:56, Eric Kom a ?crit :

Show quoted text 7 lines
Good day all; I am trying to set the Active property of TSQLTransaction to False so that I can avoid the above Read Error message: SQLTransaction: Operation cannot be performed on an active transaction The True value is currently set to True.

Try SQLTransaction.Commit or SQLTransaction.RollBack instead, depending on the case. Afterwards you can do whatever you need with the transaction. Do not use the Retaining methods as they do not desactivate the transaction. If the underlying database is Firebird, use Commit preferably to RollBack unless the former job has to be really rollbacked.

Antonio.

Reply by email

Eric Kom
to Antonio Fortuny
Antonio Fortuny wrote 15 lines
Le 04/06/2013 09:56, Eric Kom a ?crit : > Good day all; > > I am trying to set the Active property of TSQLTransaction to False so > that I can avoid the above Read Error message: > SQLTransaction: Operation cannot be performed on an active transaction > The True value is currently set to True. > Try SQLTransaction.Commit or SQLTransaction.RollBack instead, depending on the case. Afterwards you can do whatever you need with the transaction. Do not use the Retaining methods as they do not desactivate the transaction. If the underlying database is Firebird, use Commit preferably to RollBack unless the former job has to be really rollbacked.

Thanks, I did changed to Commit and then caNone before it solved the error, another error message pop up saying Access Violation. Anyway, the problem was solved.

The above code its giving me a problem; the SQLQuery do not changed according to the condition for exemple if the first condition matched, the second condition is still going to use the matching from the first and vice versa.

          else if  (cbbList.Items[cbbList.ItemIndex] = lisList1) then begin
               DataModuleConn.SQLTransaction1.Active:=True;
               DataModuleConn.SQLQuery1.SQL.Text:='SELECT year, country,
gender FROM reiser WHERE country = ''Dutch Republic''';
               DBGrid1.DataSource.DataSet:=DataModuleConn.SQLQuery1;
               DBGrid1.DataSource:=DataModuleConn.Datasource;
               DBGrid1.DataSource.DataSet.Active:=True;
               //DataModuleConn.SQLTransaction1.Commit;
               DataModuleConn.SQLTransaction1.CommitRetaining;
          end
          else if  (cbbList.Items[cbbList.ItemIndex] = lisList1) then begin
               DataModuleConn.SQLTransaction1.Active:=True;
               DataModuleConn.SQLQuery1.SQL.Text:='SELECT year, country,
gender FROM reiser WHERE country = ''Holland''';
               DBGrid1.DataSource.DataSet:=DataModuleConn.SQLQuery1;
               DBGrid1.DataSource:=DataModuleConn.Datasource;
               DBGrid1.DataSource.DataSet.Active:=True;
               //DataModuleConn.SQLTransaction1.Commit;
               DataModuleConn.SQLTransaction1.CommitRetaining;
          end;

I have tried DataModuleConn.SQLTransaction1.Rollback also, still the same.

Show quoted text 10 lines
Antonio. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Kind Regards Eric Kom System Administrator & Programmer - Metropolitan College _________________________________________ / You are scrupulously honest, frank, and \ | straightforward. Therefore you have few | \ friends. / ----------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| Kom | ) /'\_ _/`\ \___)=(___/ 2 Hennie Van Till, White River, 1240 Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334 | www.kom.za.net | www.kom.za.org | www.erickom.co.za Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5

Reply by email

Antonio Fortuny
to Eric Kom

Le 04/06/2013 16:54, Eric Kom a ?crit :

Show quoted text 14 lines
On 04/06/2013 10:19, Antonio Fortuny wrote: > Thanks, I did changed to Commit and then caNone before it solved the error, another error message pop up saying Access Violation. Anyway, the problem was solved. The above code its giving me a problem; the SQLQuery do not changed according to the condition for exemple if the first condition matched, the second condition is still going to use the matching from the first and vice versa. else if (cbbList.Items[cbbList.ItemIndex] = lisList1) then begin DataModuleConn.SQLTransaction1.Active:=True;

Use DataModuleConn.SQLTransaction1.StartTransaction instead, it is more readable ans standard
Also, if you commit or rollback the transaction most of the DataSet based components close their datasets as well. This means that the original transaction must be InTransaction for the grid to display the collected data. The transaction can be shared by all DataSet descendants though.

Show quoted text 34 lines
DataModuleConn.SQLQuery1.SQL.Text:='SELECT year, country, gender FROM reiser WHERE country = ''Dutch Republic'''; DBGrid1.DataSource.DataSet:=DataModuleConn.SQLQuery1; DBGrid1.DataSource:=DataModuleConn.Datasource; DBGrid1.DataSource.DataSet.Active:=True; //DataModuleConn.SQLTransaction1.Commit; DataModuleConn.SQLTransaction1.CommitRetaining; end else if (cbbList.Items[cbbList.ItemIndex] = lisList1) then begin DataModuleConn.SQLTransaction1.Active:=True; DataModuleConn.SQLQuery1.SQL.Text:='SELECT year, country, gender FROM reiser WHERE country = ''Holland'''; DBGrid1.DataSource.DataSet:=DataModuleConn.SQLQuery1; DBGrid1.DataSource:=DataModuleConn.Datasource; DBGrid1.DataSource.DataSet.Active:=True; //DataModuleConn.SQLTransaction1.Commit; DataModuleConn.SQLTransaction1.CommitRetaining; end; I have tried DataModuleConn.SQLTransaction1.Rollback also, still the same. > > Antonio. > > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >

Reply by email

Eric Kom
to Antonio Fortuny
Antonio Fortuny wrote 57 lines
Le 04/06/2013 16:54, Eric Kom a ?crit : > On 04/06/2013 10:19, Antonio Fortuny wrote: >> > Thanks, I did changed to Commit and then caNone before it solved the > error, another error message pop up saying Access Violation. Anyway, > the problem was solved. > > The above code its giving me a problem; the SQLQuery do not changed > according to the condition for exemple if the first condition > matched, the second condition is still going to use the matching from > the first and vice versa. > > else if (cbbList.Items[cbbList.ItemIndex] = lisList1) then > begin > DataModuleConn.SQLTransaction1.Active:=True; Use DataModuleConn.SQLTransaction1.StartTransaction instead, it is more readable ans standard Also, if you commit or rollback the transaction most of the DataSet based components close their datasets as well. This means that the original transaction must be InTransaction for the grid to display the collected data. The transaction can be shared by all DataSet descendants though. > DataModuleConn.SQLQuery1.SQL.Text:='SELECT year, country, gender FROM > reiser WHERE country = ''Dutch Republic'''; > DBGrid1.DataSource.DataSet:=DataModuleConn.SQLQuery1; > DBGrid1.DataSource:=DataModuleConn.Datasource; > DBGrid1.DataSource.DataSet.Active:=True; > //DataModuleConn.SQLTransaction1.Commit; > DataModuleConn.SQLTransaction1.CommitRetaining; > end > else if (cbbList.Items[cbbList.ItemIndex] = lisList1) then > begin > DataModuleConn.SQLTransaction1.Active:=True; > DataModuleConn.SQLQuery1.SQL.Text:='SELECT year, > country, gender FROM reiser WHERE country = ''Holland'''; > DBGrid1.DataSource.DataSet:=DataModuleConn.SQLQuery1; > DBGrid1.DataSource:=DataModuleConn.Datasource; > DBGrid1.DataSource.DataSet.Active:=True; > //DataModuleConn.SQLTransaction1.Commit; > DataModuleConn.SQLTransaction1.CommitRetaining; > end; > > I have tried DataModuleConn.SQLTransaction1.Rollback also, still > the same. >> >> Antonio. >> >> >> -- >> _______________________________________________ >> Lazarus mailing list >> >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >> > >

Hi all,

I tried reviewed the code and commented the try...except statement for more debug:

procedure TfrmMainWindow.bitBtn1Click(Sender: TObject);
begin
//try
      DataModuleConn.openConnection;
      DataModuleConn.MySQL55Conn.Transaction   :=
DataModuleConn.SQLTransaction;
      //DataModuleConn.MySQL55Conn.Transaction.Active:=False;
DataModuleConn.SQLTransaction.DataBase:=DataModuleConn.MySQL55Conn;
      DataModuleConn.SQLQuery.DataBase:=DataModuleConn.MySQL55Conn;
DataModuleConn.SQLQuery.Transaction:=DataModuleConn.SQLTransaction;
      DataModuleConn.SQLQuery.Active:=False;
      DataModuleConn.SQLQuery.SQL.Text:='';
      DataModuleConn.Datasource.DataSet:=DataModuleConn.SQLQuery;
      DataModuleConn.Datasource.DataSet.Active:=False;
      //DBGrid1.DataSource.DataSet.Active:=False;
      DBGrid1.DataSource:=DataModuleConn.Datasource;
      DBNavigator.DataSource:=DataModuleConn.Datasource;
      if  DataModuleConn.MySQL55Conn.Connected=True then begin
          frmMainWindow.memReports.Append(msgOpeningDB);
          frmMainWindow.memReports.Append(msgDBReady);
      end;
      if  (cbbList1.Items[cbbList1.ItemIndex] = 'ALL') then begin
           DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year,
country FROM reiser';
      end
      else if  (cbbList1.Items[cbbList1.ItemIndex] = lisCountry1) then begin
           DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year,
country FROM reiser WHERE country = ''Dutch Republic''';
      end
      else //(cbbList1.Items[cbbList1.ItemIndex] = lisCountry3)
      begin
         DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, country
FROM reiser WHERE country = ''Holland''';
      end;
      //DataModuleConn.SQLTransaction.StartTransaction;
      DataModuleConn.SQLQuery.Close;
      DataModuleConn.Datasource.DataSet.Active:=True;
      DataModuleConn.SQLQuery.Open;
   //except
   //   frmMainWindow.memReports.Append(ErrConnectionFailed);
   //end;
end;

The first trigged for the procedure bitBtn1Click1 works fine, the second trigged give up, with the above error:

Operation cannot be performed on an active dataset.

Press OK to ignore and risk data corruption.
Press Cancel to kill the program.

I tried to close and open the Dataset on my procedure bitBtn1Click1.

May you please assist me?

Show quoted text 8 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Kind Regards Eric Kom System Administrator & Programmer - Metropolitan College _________________________________________ / You are scrupulously honest, frank, and \ | straightforward. Therefore you have few | \ friends. / ----------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| Kom | ) /'\_ _/`\ \___)=(___/ 2 Hennie Van Till, White River, 1240 Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334 | www.kom.za.net | www.kom.za.org | www.erickom.co.za Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5

Reply by email

Antonio Fortuny
to Eric Kom

Hi all,

Show quoted text 57 lines
I tried reviewed the code and commented the try...except statement for more debug: procedure TfrmMainWindow.bitBtn1Click(Sender: TObject); begin //try DataModuleConn.openConnection; DataModuleConn.MySQL55Conn.Transaction := DataModuleConn.SQLTransaction; //DataModuleConn.MySQL55Conn.Transaction.Active:=False; DataModuleConn.SQLTransaction.DataBase:=DataModuleConn.MySQL55Conn; DataModuleConn.SQLQuery.DataBase:=DataModuleConn.MySQL55Conn; DataModuleConn.SQLQuery.Transaction:=DataModuleConn.SQLTransaction; DataModuleConn.SQLQuery.Active:=False; DataModuleConn.SQLQuery.SQL.Text:=''; DataModuleConn.Datasource.DataSet:=DataModuleConn.SQLQuery; DataModuleConn.Datasource.DataSet.Active:=False; //DBGrid1.DataSource.DataSet.Active:=False; DBGrid1.DataSource:=DataModuleConn.Datasource; DBNavigator.DataSource:=DataModuleConn.Datasource; if DataModuleConn.MySQL55Conn.Connected=True then begin frmMainWindow.memReports.Append(msgOpeningDB); frmMainWindow.memReports.Append(msgDBReady); end; if (cbbList1.Items[cbbList1.ItemIndex] = 'ALL') then begin DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, country FROM reiser'; end else if (cbbList1.Items[cbbList1.ItemIndex] = lisCountry1) then begin DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, country FROM reiser WHERE country = ''Dutch Republic'''; end else //(cbbList1.Items[cbbList1.ItemIndex] = lisCountry3) begin DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, country FROM reiser WHERE country = ''Holland'''; end; //DataModuleConn.SQLTransaction.StartTransaction; DataModuleConn.SQLQuery.Close; DataModuleConn.Datasource.DataSet.Active:=True; DataModuleConn.SQLQuery.Open; //except // frmMainWindow.memReports.Append(ErrConnectionFailed); //end; end; The first trigged for the procedure bitBtn1Click1 works fine, the second trigged give up, with the above error: Operation cannot be performed on an active dataset.

Could you point out which line generates the error ? As a matter of fact, there are too much DB related operations. For instance the first 9 lines after the one // Try should be moved somewhere in an independent method and called only once in some intialization routine.
Secondly, the two next lines do exactle the same thing, only one of them should be removed

      DataModuleConn.Datasource.DataSet.Active:=True;     <==== keep

this one as more datasource independent
DataModuleConn.SQLQuery.Open; <---------- this one can be removed

This rearrangement should work provided the 9 preceeding lines have been moved somewhere else and executed at least once

      if DataModuleConn.SQLQuery.Active then
          DataModuleConn.SQLQuery.Close;
     if DataModuleConn.MySQL55Conn.Transaction.InTransaction then
         DataModuleConn.MySQL55Conn.Transaction.Commit;
      if  DataModuleConn.MySQL55Conn.Connected=True then begin
          frmMainWindow.memReports.Append(msgOpeningDB);
          frmMainWindow.memReports.Append(msgDBReady);
      end;
      if  (cbbList1.Items[cbbList1.ItemIndex] = 'ALL') then begin
           DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year,
country FROM reiser';
      end
      else if  (cbbList1.Items[cbbList1.ItemIndex] = lisCountry1) then
begin
           DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year,
country FROM reiser WHERE country = ''Dutch Republic''';
      end
      else //(cbbList1.Items[cbbList1.ItemIndex] = lisCountry3)
      begin
         DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, country
FROM reiser WHERE country = ''Holland''';
      end;
      DataModuleConn.SQLTransaction.StartTransaction;
      DataModuleConn.SQLQuery.Open;

Antonio.

Show quoted text 17 lines
Press OK to ignore and risk data corruption. Press Cancel to kill the program. I tried to close and open the Dataset on my procedure bitBtn1Click1. May you please assist me? > > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >
Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130606/68738299/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: bjebcbje.jpg Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130606/68738299/attachment-0002.jpg> -------------- next part -------------- A non-text attachment was scrubbed... Name: idiiejja.jpg Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130606/68738299/attachment-0003.jpg>

Reply by email

Eric Kom
to Antonio Fortuny
Antonio Fortuny wrote 59 lines
Hi all, > > I tried reviewed the code and commented the try...except statement > for more debug: > > procedure TfrmMainWindow.bitBtn1Click(Sender: TObject); > begin > //try > DataModuleConn.openConnection; > DataModuleConn.MySQL55Conn.Transaction := > DataModuleConn.SQLTransaction; > //DataModuleConn.MySQL55Conn.Transaction.Active:=False; > DataModuleConn.SQLTransaction.DataBase:=DataModuleConn.MySQL55Conn; > DataModuleConn.SQLQuery.DataBase:=DataModuleConn.MySQL55Conn; > DataModuleConn.SQLQuery.Transaction:=DataModuleConn.SQLTransaction; > DataModuleConn.SQLQuery.Active:=False; > DataModuleConn.SQLQuery.SQL.Text:=''; > DataModuleConn.Datasource.DataSet:=DataModuleConn.SQLQuery; > DataModuleConn.Datasource.DataSet.Active:=False; > //DBGrid1.DataSource.DataSet.Active:=False; > DBGrid1.DataSource:=DataModuleConn.Datasource; > DBNavigator.DataSource:=DataModuleConn.Datasource; > > if DataModuleConn.MySQL55Conn.Connected=True then begin > frmMainWindow.memReports.Append(msgOpeningDB); > frmMainWindow.memReports.Append(msgDBReady); > end; > > if (cbbList1.Items[cbbList1.ItemIndex] = 'ALL') then begin > DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, > country FROM reiser'; > end > > else if (cbbList1.Items[cbbList1.ItemIndex] = lisCountry1) then > begin > DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, > country FROM reiser WHERE country = ''Dutch Republic'''; > end > else //(cbbList1.Items[cbbList1.ItemIndex] = lisCountry3) > begin > DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, > country FROM reiser WHERE country = ''Holland'''; > end; > > //DataModuleConn.SQLTransaction.StartTransaction; > DataModuleConn.SQLQuery.Close; > DataModuleConn.Datasource.DataSet.Active:=True; > DataModuleConn.SQLQuery.Open; > > //except > // frmMainWindow.memReports.Append(ErrConnectionFailed); > //end; > end; > > The first trigged for the procedure bitBtn1Click1 works fine, the > second trigged give up, with the above error: > > Operation cannot be performed on an active dataset. Could you point out which line generates the error ?

Thank you for your response
No specific line has been reported.
According to the error message, for another query to be executed, the Dataset must be turn to false so that previous query must be cancelled.

Show quoted text 17 lines
As a matter of fact, there are too much DB related operations. For instance the first 9 lines after the one // Try should be moved somewhere in an independent method and called only once in some intialization routine. Secondly, the two next lines do exactle the same thing, only one of them should be removed DataModuleConn.Datasource.DataSet.Active:=True; <==== keep this one as more datasource independent DataModuleConn.SQLQuery.Open; <---------- this one can be removed This rearrangement should work provided the 9 preceeding lines have been moved somewhere else and executed at least once if DataModuleConn.SQLQuery.Active then DataModuleConn.SQLQuery.Close; if DataModuleConn.MySQL55Conn.Transaction.InTransaction then

on the DataModuleConn.MySQL55Conn.Transaction.InTransaction, the InTransaction property/var its not reorganized by lazarus.

Show quoted text 62 lines
DataModuleConn.MySQL55Conn.Transaction.Commit; if DataModuleConn.MySQL55Conn.Connected=True then begin frmMainWindow.memReports.Append(msgOpeningDB); frmMainWindow.memReports.Append(msgDBReady); end; if (cbbList1.Items[cbbList1.ItemIndex] = 'ALL') then begin DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, country FROM reiser'; end else if (cbbList1.Items[cbbList1.ItemIndex] = lisCountry1) then begin DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, country FROM reiser WHERE country = ''Dutch Republic'''; end else //(cbbList1.Items[cbbList1.ItemIndex] = lisCountry3) begin DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, country FROM reiser WHERE country = ''Holland'''; end; DataModuleConn.SQLTransaction.StartTransaction; DataModuleConn.SQLQuery.Open; Antonio. > Press OK to ignore and risk data corruption. > Press Cancel to kill the program. > > I tried to close and open the Dataset on my procedure bitBtn1Click1. > > May you please assist me? > >> >> >> -- >> _______________________________________________ >> Lazarus mailing list >> >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >> > > -- Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Kind Regards Eric Kom System Administrator & Programmer - Metropolitan College _________________________________________ / You are scrupulously honest, frank, and \ | straightforward. Therefore you have few | \ friends. / ----------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| Kom | ) /'\_ _/`\ \___)=(___/ 2 Hennie Van Till, White River, 1240 Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334 | www.kom.za.net | www.kom.za.org | www.erickom.co.za Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130606/8b010049/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130606/8b010049/attachment.jpe> -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130606/8b010049/attachment-0001.jpe>

Reply by email

Eric Kom
to Eric Kom
Eric Kom wrote 115 lines
On 06/06/2013 15:17, Antonio Fortuny wrote: > Hi all, >> >> I tried reviewed the code and commented the try...except statement >> for more debug: >> >> procedure TfrmMainWindow.bitBtn1Click(Sender: TObject); >> begin >> //try >> DataModuleConn.openConnection; >> DataModuleConn.MySQL55Conn.Transaction := >> DataModuleConn.SQLTransaction; >> //DataModuleConn.MySQL55Conn.Transaction.Active:=False; >> DataModuleConn.SQLTransaction.DataBase:=DataModuleConn.MySQL55Conn; >> DataModuleConn.SQLQuery.DataBase:=DataModuleConn.MySQL55Conn; >> DataModuleConn.SQLQuery.Transaction:=DataModuleConn.SQLTransaction; >> DataModuleConn.SQLQuery.Active:=False; >> DataModuleConn.SQLQuery.SQL.Text:=''; >> DataModuleConn.Datasource.DataSet:=DataModuleConn.SQLQuery; >> DataModuleConn.Datasource.DataSet.Active:=False; >> //DBGrid1.DataSource.DataSet.Active:=False; >> DBGrid1.DataSource:=DataModuleConn.Datasource; >> DBNavigator.DataSource:=DataModuleConn.Datasource; >> >> if DataModuleConn.MySQL55Conn.Connected=True then begin >> frmMainWindow.memReports.Append(msgOpeningDB); >> frmMainWindow.memReports.Append(msgDBReady); >> end; >> >> if (cbbList1.Items[cbbList1.ItemIndex] = 'ALL') then begin >> DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, >> country FROM reiser'; >> end >> >> else if (cbbList1.Items[cbbList1.ItemIndex] = lisCountry1) >> then begin >> DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, >> country FROM reiser WHERE country = ''Dutch Republic'''; >> end >> else //(cbbList1.Items[cbbList1.ItemIndex] = lisCountry3) >> begin >> DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, >> country FROM reiser WHERE country = ''Holland'''; >> end; >> >> //DataModuleConn.SQLTransaction.StartTransaction; >> DataModuleConn.SQLQuery.Close; >> DataModuleConn.Datasource.DataSet.Active:=True; >> DataModuleConn.SQLQuery.Open; >> >> //except >> // frmMainWindow.memReports.Append(ErrConnectionFailed); >> //end; >> end; >> >> The first trigged for the procedure bitBtn1Click1 works fine, the >> second trigged give up, with the above error: >> >> Operation cannot be performed on an active dataset. > Could you point out which line generates the error ? Thank you for your response No specific line has been reported. According to the error message, for another query to be executed, the Dataset must be turn to false so that previous query must be cancelled. > As a matter of fact, there are too much DB related operations. > For instance the first 9 lines after the one // Try should be moved > somewhere in an independent method and called only once in some > intialization routine. > Secondly, the two next lines do exactle the same thing, only one of > them should be removed > DataModuleConn.Datasource.DataSet.Active:=True; <==== keep this > one as more datasource independent > DataModuleConn.SQLQuery.Open; <---------- this one can > be removed > > This rearrangement should work provided the 9 preceeding lines have > been moved somewhere else and executed at least once > > if DataModuleConn.SQLQuery.Active then > DataModuleConn.SQLQuery.Close; > if DataModuleConn.MySQL55Conn.Transaction.InTransaction then on the DataModuleConn.MySQL55Conn.Transaction.InTransaction, the InTransaction property/var its not reorganized by lazarus. > DataModuleConn.MySQL55Conn.Transaction.Commit; > if DataModuleConn.MySQL55Conn.Connected=True then begin > frmMainWindow.memReports.Append(msgOpeningDB); > frmMainWindow.memReports.Append(msgDBReady); > end; > > if (cbbList1.Items[cbbList1.ItemIndex] = 'ALL') then begin > DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, > country FROM reiser'; > end > > else if (cbbList1.Items[cbbList1.ItemIndex] = lisCountry1) then > begin > DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, > country FROM reiser WHERE country = ''Dutch Republic'''; > end > else //(cbbList1.Items[cbbList1.ItemIndex] = lisCountry3) > begin > DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, > country FROM reiser WHERE country = ''Holland'''; > end; > > DataModuleConn.SQLTransaction.StartTransaction; > DataModuleConn.SQLQuery.Open; > > Antonio. >> Press OK to ignore and risk data corruption. >> Press Cancel to kill the program. >> >> I tried to close and open the Dataset on my procedure bitBtn1Click1. >> >> May you please assist me?
The following code works:
//try
      DataModuleConn.openConnection;
      if DataModuleConn.SQLQuery.Active then begin
          DataModuleConn.SQLQuery.Close;
      end;
      if DataModuleConn.SQLTransaction.Active then begin
         //DataModuleConn.MySQL55Conn.Transaction.Commit;
          DataModuleConn.SQLTransaction.Active:=True;
          DataModuleConn.SQLTransaction.Rollback;
          DataModuleConn.SQLTransaction.Active:=False;
      end;
      if  DataModuleConn.MySQL55Conn.Connected=True then begin
          frmMainWindow.memReports.Append(msgOpeningDB);
          frmMainWindow.memReports.Append(msgDBReady);
DataModuleConn.SQLTransaction.DataBase:=DataModuleConn.MySQL55Conn;
DataModuleConn.SQLQuery.DataBase:=DataModuleConn.MySQL55Conn;
DataModuleConn.SQLQuery.Transaction:=DataModuleConn.SQLTransaction;
          DataModuleConn.Datasource.DataSet:=DataModuleConn.SQLQuery;
      end;
     if  (cbbList1.Items[cbbList1.ItemIndex] = 'ALL') then begin
           DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year,
country FROM reiser';
      end
      else if  (cbbList1.Items[cbbList1.ItemIndex] = lisCountry1) then
begin
           DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year,
country FROM reiser WHERE country = ''Dutch Republic''';
      end
      else //(cbbList1.Items[cbbList1.ItemIndex] = lisCountry3)
      begin
         DataModuleConn.SQLQuery.SQL.Text:='SELECT gender, year, country
FROM reiser WHERE country = ''Holland''';
      end;
      DataModuleConn.SQLTransaction.StartTransaction;
      DataModuleConn.SQLQuery.Open;
DBGridStudentRegistration.DataSource:=DataModuleConn.Datasource;
DBNavigatorStudentRegistration.DataSource:=DataModuleConn.Datasource;
Show quoted text 66 lines
>> >>> >>> >>> -- >>> _______________________________________________ >>> Lazarus mailing list >>> >>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >>> >> >> > > -- > Sita Software > *Antonio Fortuny* > Senior Software engineer > > 220, avenue de la Libert? > L-4602 Niederkorn > Tel.: +352 58 00 93 - 93 > www.sitasoftware.lu <http://www.sitasoftware.lu> > Your IT Partner > > > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- Kind Regards Eric Kom System Administrator & Programmer - Metropolitan College _________________________________________ / You are scrupulously honest, frank, and \ | straightforward. Therefore you have few | \ friends. / ----------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| Kom | ) /'\_ _/`\ \___)=(___/ 2 Hennie Van Till, White River, 1240 Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334 www.kom.za.net |www.kom.za.org |www.erickom.co.za Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5 -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Kind Regards Eric Kom System Administrator & Programmer - Metropolitan College _________________________________________ / You are scrupulously honest, frank, and \ | straightforward. Therefore you have few | \ friends. / ----------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| Kom | ) /'\_ _/`\ \___)=(___/ 2 Hennie Van Till, White River, 1240 Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334 | www.kom.za.net | www.kom.za.org | www.erickom.co.za Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130606/093786de/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130606/093786de/attachment-0002.jpe> -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130606/093786de/attachment-0003.jpe>

Reply by email