Recent

Author Topic: Datamodule - database not assigned exception  (Read 5455 times)

talorigomat

  • Jr. Member
  • **
  • Posts: 96
Datamodule - database not assigned exception
« on: September 26, 2013, 11:56:21 pm »
I'm using lazarus 1.0.12 and firebird 2.5.  I have one form and a datamodule.  I'm using the components on the SQLdb tab.  On the datamodule I place a IBconnection and a Sqltransaction.  On the Form1 I have a SqlQuery with a simple select statement (select * from orgtable).   I also have a datasource and a datagrid on Form1.  With everything connected and active I can see the records displayed on Form1 in design view.  However when I run the program I get the following exception message: "Project project1 raised exception class 'EDatabaseError' with message Database not assigned! at address 568E38.  I've tried adding the datamodule in the form's  interface section under 'Uses' and changing the order in which the forms are created in the projects option but still get this error.

I've also done the same using the IBX for Lazarus components and still get the same error.  What am I missing?

If I get rid of the datamodule and place all the components on the form it works fine.
Lazarus 1.8.0Rc4, Windows 10

Mujie

  • Jr. Member
  • **
  • Posts: 64
Re: Datamodule - database not assigned exception
« Reply #1 on: September 27, 2013, 02:40:07 am »
Hi @talorigomat

I never use SQLdb, you could try Zeos library (http://sourceforge.net/projects/zeoslib/files/latest/download) for comparison. :)

LacaK

  • Hero Member
  • *****
  • Posts: 606
Re: Datamodule - database not assigned exception
« Reply #2 on: September 27, 2013, 06:45:08 am »
Can you attach here your project (zipped) ?

talorigomat

  • Jr. Member
  • **
  • Posts: 96
Re: Datamodule - database not assigned exception
« Reply #3 on: September 27, 2013, 07:33:14 am »
Here is a zip file containing the project.
Lazarus 1.8.0Rc4, Windows 10

LacaK

  • Hero Member
  • *****
  • Posts: 606
Re: Datamodule - database not assigned exception
« Reply #4 on: September 27, 2013, 11:43:17 am »
Put in your Organisation unit after implementation:

Code: [Select]
uses datamodule;

talorigomat

  • Jr. Member
  • **
  • Posts: 96
Re: Datamodule - database not assigned exception
« Reply #5 on: September 27, 2013, 08:13:09 pm »
Tried LacaK suggestion, and placed the Uses datamodule in the implementation section.  The program compiles successfully but gives the following message: "organisation.pas(30,6) Hint: Unit "datamodule" not used in Organisation".  If I set the dataset to active in design mode before compiling I still get the "'EDatabaseError' with message Database not assigned!" message. 

If the dataset is set to inactive the program compiles (still giving the hint) and runs.  Of course there is no data in the datagrid

I've now placed a button on the organisation form and  set the dataset to inactive.  The code in the onClick event is "dstSelect.Active := not dstSelect.Active;".  The program does compile (still giving the same hint from the compiler) but when I click the button it toggles the dataset on and I an see the data in the datagrid.

Is this behaviour normal?
Lazarus 1.8.0Rc4, Windows 10

DarthEvansHill

  • Newbie
  • Posts: 1
Re: Datamodule - database not assigned exception
« Reply #6 on: October 07, 2013, 11:16:41 am »
Hi there.  I am new on here but I have been a  Proffesional DelphiProgrammer for over 15 years. I am just getting to grips with Lazarus which is a bit different but is, in many ways, much the same and in some ways better.

Try this:(pretty sure it will work because it did when I did it on your project)
Go to Project, Project options, Forms and then look at autocreate forms.  What your doing is creating the mainform and then the datamodule.  So when your form gets created it tries to access the datamodule and because it has not been auto created yet, you get your database error.  Just highlight the datamodule and move it to the top of the list. I have had this also in Delphi a few times.
I did this and it got rid of the database error but then it went on to tell me that I have some dll's missing.  I don't have Firebird installed so I expect that's what it's telling me as it's looking for the Client DLL's, if you have Firebird installed I don't think you will get this error.  If you do I would hazard a guess that you just need to either tell Lazarus where they are or put them somewhere where Lazarus can find them.
Hope this fixes your problem.

 

TinyPortal © 2005-2018