MySql connection not working.

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
timkSPC
Posts: 4
Joined: Mon 06 Dec 2010 13:37

MySql connection not working.

Post by timkSPC » Mon 06 Dec 2010 13:51

Hello,
I am trying to connect to a MySQL database and its not working.

When I type all of the information into TUniConnection that I drop onto the main form it works, however when I create one in code and fill out the parameters with the same information it fails

Code: Select all

  Conn := TUniConnection.Create(self);
  Conn.ProviderName:= 'MySQL';
  Conn.Username:='username';
  Conn.Password:= 'Password'
  Conn.Server :=  '97.75.23.17';
  Conn.Database:= 'mydatabase';
//  Conn.Port := 3306;
  Conn.Connect;

  if Conn.Connected then
    begin
      tbl := TUniTable.Create(Self);
      tbl.Connection := Conn;
      tbl.TableName := 'Test';
      tbl.Open;

      tbl.FindFirst;
      ShowMessage(tbl.FieldByName('idTest').AsString);
    end;

  Conn.Close;
It fails when it tries to connect, and the problem I am seeing is that instead of trying to connect to the IP provided it tries to connect to the IP of my companies modem. I assume there is something I am not setting correctly considering it works through component when i drop it on the form but not in my code.

NOTE: The result is the same no matter if I set the port or not.

Thank you for your help,
Tim

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 06 Dec 2010 14:39

Hello,

Please send the message of the exception you get when trying to connect.

timkSPC
Posts: 4
Joined: Mon 06 Dec 2010 13:37

Post by timkSPC » Mon 06 Dec 2010 15:03

#28000Access denied for user 'username'@'myrouterip' (using password: YES)
Sorry it slipped my mind to post it.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 07 Dec 2010 10:49

Hello,

This error indicates that you are using incorrect user name or password. Please check your user name and password.

timkSPC
Posts: 4
Joined: Mon 06 Dec 2010 13:37

Post by timkSPC » Tue 07 Dec 2010 12:39

The error msg is not the best indication of the problem. The ip address it is trying to connect to is different than the ip address i set in code


for example: I set Conn.Server = '97.75.23.17' and when it tries to connect it tries to connect to '75.19.123.113'

note: I am not showing the actual ip addresses.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 07 Dec 2010 14:35

Hello,

Please specify the application that you are using to check ip-address where you are trying to connect.
Also if, as you say, UniDAC tried to connect to your 'companies modem' then you couldn't have got the error specified above.
Please check that you have permission to connect to a server using your user name and your host. Also please try to connect using third-party applications, and send me the result.
We don't change the Server property in the code if it is set as an ip-address.

timkSPC
Posts: 4
Joined: Mon 06 Dec 2010 13:37

Post by timkSPC » Tue 07 Dec 2010 15:52

Please specify the application that you are using to check ip-address where you are trying to connect.

My test application, in code i set it to 97.75.23.17 and the error message says it was trying to connect to 75.19.123.113. This IP is the address of my router (Found by "Tracert 75.19.123.113 and confirmed by coworker)

Also if, as you say, UniDAC tried to connect to your 'companies modem' then you couldn't have got the error specified above.

I did. And it might make sense too. Somewhere along the way the ip address I'm trying to connect to got changed to my routerip...(or so it seems) and I can't connect to it (not that i want to)

Please check that you have permission to connect to a server using your user name and your host. Also please try to connect using third-party applications, and send me the result.

I can connect without any problem using MySQL workbench. Also if I drop a TUniDac Component onto the form, double click on it, set all of the information into that form and click connect then it works and says connected.


I appreciate all of your help. I'd think I'm just missing something in my code but I don't know what.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Wed 08 Dec 2010 10:37

Hello,

Please send the screenshot of the error message, the exact version of UniDAC, and the version of your IDE to alexp*devart*com.
Also please add the UniDacVcl unit to the uses section, set the correct connection information into the connection dialog, and try to connect.

Post Reply