Forum > Databases

Error - Transaction of connection not set

(1/9) > >>

valdir.marcos:
Why IBConnection component looses its information about the default SQLTransaction component after first run?

Important detail: I am using a second SQLTransaction for a SQLQuery.

I have attached a small example:
- Run the project;
- Click Button1 to open Form2;
- Click Button3 to run query. It works correctly;
- Close Form2;

- Click Button1 AGAIN to reopen Form2;
- Click Button3 to run query. It gives error "Transaction of connection not set".

EDatabaseError, SErrConnTransactionnSet, Transaction of connection not set

mangakissa:
Wrong approach. Use Datamodule.
It looks like your sample is loosing the connection to Form1 after de caFree. Could be a bug, but I'm not sure.
The datamodule has all it needs: the connection and query at one page. THe RTTI doesn't have to search where your component are put.

valdir.marcos:

--- Quote from: mangakissa on September 01, 2018, 09:01:34 am ---Wrong approach. Use Datamodule.
--- End quote ---
The real application uses datamodules and the problem is spread in hundreds of forms.


--- Quote ---It looks like your sample is loosing the connection to Form1 after de caFree. Could be a bug, but I'm not sure.
--- End quote ---
I am trying to confirm the problem before open a bug report.


--- Quote ---The datamodule has all it needs: the connection and query at one page. THe RTTI doesn't have to search where your component are put.
--- End quote ---
The real application uses datamodules to center what is general, like IBConnection; but SQLTransaction and SQLQuery belong to forms, just like in the old Delphi application that is being converted to Lazarus.

valdir.marcos:

--- Quote from: mangakissa on September 01, 2018, 09:01:34 am ---The datamodule has all it needs: the connection and query at one page. THe RTTI doesn't have to search where your component are put.
--- End quote ---
I really appreciate your help, but your solution is not consistent for this case.
I can't have dozens of connections and hundreds of transactions and tables in only one data module.
This is an old application in Delphi that is being migrated to Lazarus.
There are hundreds of forms that contain between 1 and 3 tables.
Having a data module for each form would be a huge waste of resources.
In addition, there is only one connection for each database in the central data module. We only create an individual data module for each form when it needs many tables. Even in this case, the individual data module uses one of the connections that are in the central data module.

mangakissa:
The whole idea of using databases and GUI is seperating those things . Your form doesn't have to know how your query is connected.

--- Quote ---I can't have dozens of connections and hundreds of transactions and tables in only one data module.
--- End quote ---
Your wrong. One datamodule is is global and runinng the connection. All other queries for each form can have his own datamodule.

--- Quote ---Having a data module for each form would be a huge waste of resources.
--- End quote ---
That's only when you open them all at once. Just create the datamodule when you open your form.

--- Quote ---This is an old application in Delphi that is being migrated to Lazarus.
--- End quote ---
So the developping of the program was wrong in the beginning.

--- Quote ---n addition, there is only one connection for each database in the central data module. We only create an individual data module for each form when it needs many tables. Even in this case, the individual data module uses one of the connections that are in the central data module.
--- End quote ---
First you tell all datacomponents ar on the form. Second you tell there's a an individual datamodule for each form. I'm confused write now.

I'll give an solution bases on your example.

I create a a large application over 60 forms and use 10 to 12 datamodules. I'm just open the datamodule I need for the form. All my connections to the database (except Tdatasource) doesn't know nothing about my databas. When I want a form rebuild, the connection the the database will be the same. Just connecting the form to the datamodule.

My approach is: Form  <--> class object <--> datamodule

Navigation

[0] Message Index

[#] Next page

Go to full version