Recent

Author Topic: [SOLVED] Too Many Database Components?  (Read 3911 times)

guest48180

  • Guest
[SOLVED] Too Many Database Components?
« on: May 31, 2018, 03:27:43 pm »
I hate to bother everyone (again), but I'd rather ask before I start tearing apart a lot of work and messing stuff up.

I have two forms that use the same database. There will be several more by the time i finish, but just two for now.

On one form, the main one, I have three grids. On it I have:
  • 3 DataSources
  • 3 SQLQueries
  • 1 SQLite3Connection
  • 1 SQLTransaction
That works perfectly.
On the second form, I added (yet again):
  • 1 DataSource
  • 1 SQLQuery
  • 1 SQLite3Connection
  • 1 SQLTransaction
When I switch between forms, I'm finiding all of this is tangling up on me, causing the database to keep locking up. So when I started disconnecting them through code, my grids stopped displaying data until I clicked the Refresh button.

I don't need those other data components on the second form, right? I've already seen that, by adding the main form to the uses of the second form, I can access the main form's data components. Everything works right now, but the grids going blank is kinda ugly  :D

af0815

  • Hero Member
  • *****
  • Posts: 1288
Re: Too Many Database Components?
« Reply #1 on: May 31, 2018, 03:54:14 pm »
Why 2 Connections and transaction ?

Put the connection and the transaction in a Datamodule (eg. spezialized Form) and connect the Queries on both forms to it.

If you use 2 connection it looks like 2 user for the DB and produce locking.
regards
Andreas

guest48180

  • Guest
Re: Too Many Database Components?
« Reply #2 on: May 31, 2018, 04:08:30 pm »
Why 2 Connections and transaction ?

Put the connection and the transaction in a Datamodule (eg. spezialized Form) and connect the Queries on both forms to it.

If you use 2 connection it looks like 2 user for the DB and produce locking.

So just pull off the connection and transaction and put them in a datamodule? I'll try that. I'd shied away from using a datamodule because it gave me a lot of trouble yesterday as I set up a Master/Detail configuration. That's why I stuck all my components on the main form. But when I started coding the second form earlier, I dropped the needed four components on it too. That's when things got goofy. I'll do as you said. Thanks a lot, af0815.

af0815

  • Hero Member
  • *****
  • Posts: 1288
Re: Too Many Database Components?
« Reply #3 on: May 31, 2018, 04:28:05 pm »
Where the connection and the transaction reside is meaningless. Your trouble is, you build two connetions to the database. If you use differenet DB it is ok.

See https://stackoverflow.com/questions/10325683/can-i-read-and-write-to-a-sqlite-database-concurrently-from-multiple-connections for some explenation.
 
In short, for each sqlite-DB only one Connection/transaction. Normally there is no problem with a Datamodule, but it is only for non visual componnets. The second is, look for the right creation order of your forms (DM is like a form). I think your problem was the order of creating the forms. Normally problems coming if the Form with the visual components are created first and cannot bound to the later created components on the Datamodule.

 
regards
Andreas

guest48180

  • Guest
Re: Too Many Database Components?
« Reply #4 on: May 31, 2018, 04:39:34 pm »
Thank you for your very clear answer, af0815. You've helped me a lot. Thanks.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: [SOLVED] Too Many Database Components?
« Reply #5 on: June 01, 2018, 08:56:10 am »
look at the demo I attached
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

guest48180

  • Guest
Re: [SOLVED] Too Many Database Components?
« Reply #6 on: June 01, 2018, 03:59:38 pm »
Hi mangakissa. Thanks for sharing. What you showed me is what I've been trying to do for the past 2 or 3 days. Here are my efforts:

https://ufile.io/jfk1o

I cldn't put it here, even after removing the program file. I'm sure my work's crude compared to what most here can do, but I'm trying. The Edit page isn't wired up. The Financial side has nothing yet. This is something my girlfriend asked me to do for her. Take a look and tell me what and where I can improve on. I'm open to constructive criticism and good advice that'll further my knowledge and understanding.

Thanks.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: [SOLVED] Too Many Database Components?
« Reply #7 on: June 01, 2018, 09:30:32 pm »
I can't download your file. But if you take only the *.pas, *.lfm and lpi file in a zip you can upload here to share it for other members
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

guest48180

  • Guest
Re: [SOLVED] Too Many Database Components?
« Reply #8 on: June 01, 2018, 09:39:09 pm »
Here they are. Like I said, my work's crude compared to what most here can do. But it's a beginning  ;)

Comments and advice are welcome. Thanks.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: [SOLVED] Too Many Database Components?
« Reply #9 on: June 02, 2018, 02:52:46 am »
Here they are. Like I said, my work's crude compared to what most here can do. But it's a beginning  ;)

Comments and advice are welcome. Thanks.
I'm going to take a closer look at your code later tonight. A fast observation, you did not include the project1.lpr file, not a big deal for this one, for now consider it just a FYI, this is a needed file, lpi on the other hand not so much.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

guest48180

  • Guest
Re: [SOLVED] Too Many Database Components?
« Reply #10 on: June 02, 2018, 03:01:37 am »
Hi taazz. Here's the needed files. Sorry about that  :D

 

TinyPortal © 2005-2018