Recent

Author Topic: [SOLVED] Problem with migration from 1.6.2 to 1.8.0  (Read 5203 times)

melwinek

  • Jr. Member
  • **
  • Posts: 60
[SOLVED] Problem with migration from 1.6.2 to 1.8.0
« on: December 07, 2017, 09:55:07 pm »
I my application I create Form1 in project1.lpr.
In Form1 i have PQConnection with many SQLQuery and many DbGrids.
My Form1.OnCreate is empty.
In Form1.OnShow I create FormLogin in which I set the PQConnection parameters, hostname, port, username, password, etc.

Next I set SQL properties and open my SQLQueries.

In 1.6.2 everything was fine.
In 1.8.0, the program shows a connection error with address 127.0.0.1.
It looks like PQConnection has tried to connect itself. Before I set parameters and open them.

Why is it like that ?
« Last Edit: December 10, 2017, 10:56:01 pm by melwinek »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #1 on: December 08, 2017, 05:14:59 am »
what is the value of the connected property in object inspector?
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

melwinek

  • Jr. Member
  • **
  • Posts: 60
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #2 on: December 08, 2017, 07:47:35 am »
Value of connected property in PQConnection is False;

melwinek

  • Jr. Member
  • **
  • Posts: 60
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #3 on: December 08, 2017, 08:24:07 pm »
my project.lpr:
Code: Pascal  [Select][+][-]
  1. begin
  2.   Application.Initialize;
  3.   Application.CreateForm(TForm1, Form1);
  4.   Application.Run;
  5. end.

my Unit1.pas:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormShow(Sender: TObject);
  2. begin
  3. user1:='';
  4. Application.CreateForm(TFormLogin, FormLogin);
  5. FormLogin.ShowModal;
  6. if user1='' then
  7.   Application.Terminate
  8. else
  9. begin
  10. .......
       

my unitlogin.pas:
Code: Pascal  [Select][+][-]
  1. procedure TFormLogin.FormShow(Sender: TObject);
  2. var test:integer;
  3. begin
  4. if FileExists('test') then test:=1 else test:=0;
  5.  
  6. if test=1 then
  7. begin
  8.   Form1.PQConnection1.Hostname:='x.x.x.x';
  9.   Form1.PQConnection1.Params.Text:='port=xxxx';
  10.   Form1.Caption:=Form1.Caption+' (TEST)';
  11. end
  12. else
  13. begin
  14.   Form1.PQConnection1.Hostname:='y.y.y.y';
  15.   Form1.PQConnection1.Params.Text:='port=yyyy';
  16. end;
  17. Form1.PQConnection1.Connected:=True;    
  18. ......
  19. //// login etc....

error:
PQConnection: Connection to database failed
.......
Is the server running on host "localhost" (127.0.0.1)....

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #4 on: December 08, 2017, 08:47:40 pm »
the connection to the database should happen after the user presses the login/ok button on the login form not on the onShow event of that form. From the code you provided I would say that either 'x.x.x.x' or 'y.y.y.y' is the 127.0.0.1. I would build with debug information add a break point on the line if FileExists('Test') then.... and see if the exception occurs before the end break point or after.
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

melwinek

  • Jr. Member
  • **
  • Posts: 60
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #5 on: December 08, 2017, 11:08:27 pm »
Connection to the database can not happen after clicking the login button, because list of users to the combobox is downloaded from the database. Password is also compared to the database.
x.x.x.x and y.y.y.y is not 127.0.0.1.
Hostname property in PQConnection1 is blank. Maybe 127.0.0.1 is default.
When i insert ShowMessage command after begin in Unit1 in procedure TForm1.FormShow, this message does not show up. But the connection error yes.

melwinek

  • Jr. Member
  • **
  • Posts: 60
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #6 on: December 10, 2017, 09:36:54 pm »
After error program stop in function: InitLazResourceComponent, in Unit LResources, in line 3184: NotifyGlobalLoading;

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #7 on: December 10, 2017, 09:48:34 pm »
What happens if you set the scoExplicitConnect to true in the options of your PQConnection component?

And are you sure all your SQLQuery's are not set to Active = true?

melwinek

  • Jr. Member
  • **
  • Posts: 60
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #8 on: December 10, 2017, 09:59:03 pm »
When i set scoExplicitConnect to True i get error message: "Error: attempt implicity activate connection PQConnection1"

All SQLQuery'a is set Active := False.

Why in 1.6.2 all working correct ?

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #9 on: December 10, 2017, 10:05:51 pm »
When i set scoExplicitConnect to True i get error message: "Error: attempt implicity activate connection PQConnection1"
Then there is something that tries to set the connection to active before you change the connection parameters.

Some Active on the datasets could cause that but you say they are all false.

Maybe you can create a small test-project with just one query and dbgrid and see if it happens there too. If it does you can put it here and we can see if it is really a bug.


rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #10 on: December 10, 2017, 10:24:12 pm »
Just tested TPQConnection without setting it to Connected and it worked fine.

Maybe you can (after backup) delete/strip some TSQLQueries and TDBGrids until your application does work.

Also check any event handler which might trigger a connect (or active on a dataset). They can fire before you have the ability to login.

melwinek

  • Jr. Member
  • **
  • Posts: 60
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #11 on: December 10, 2017, 10:31:20 pm »
I found a problem.
I have the Combobox.onchange procedure.
In this procedure, I open one QUERY.
Why this procedure is called when creating a form, I have no idea.
At the moment I've created a variable that I give a value after connect to the database.
In the Combobobox.onchange procedure, I check if the variable has this value.
This is a workaround, but it's enough for this moment.

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: Problem with migration from 1.6.2 to 1.8.0
« Reply #12 on: December 10, 2017, 10:35:00 pm »
I have the Combobox.onchange procedure.
In this procedure, I open one QUERY.
Yep. Event problem  ;D

Quote
At the moment I've created a variable that I give a value after connect to the database. In the Combobobox.onchange procedure, I check if the variable has this value.
You can just use PQConnection.Connected  :D
Code: Pascal  [Select][+][-]
  1. begin
  2.   if not PQConnection.Connected then exit;
  3.   // do you thing
  4. end;

melwinek

  • Jr. Member
  • **
  • Posts: 60
Re: [SOLVED] Problem with migration from 1.6.2 to 1.8.0
« Reply #13 on: December 10, 2017, 10:56:17 pm »
Right.
I always do everything around :)

 

TinyPortal © 2005-2018