Unable to connect to mySql database useing just code

I searched here but did not see an answer .

I am using Delphi2010. I using Devart Mydac to connect to mySql data base . When i set the Server, Database, Name , Pass in the component it connects no problem.

BUt when I try to connect just with code it give an error.

begin
    MyConnection1.Server:='MyServer';
    MyConnection1.Database:='MyDatabase';
    MyConnection1.Username:='MyUserName';
    MyConnection1.Password:='MyPassword';
    MyConnection1.Connected:= True;
    MyQuery1.Active:= True;
end;   

exception class EMySalExcption with message"#28000 Access denied for user'username@00.00.00.00'(useing passworkd: YES)'.

Why will the code method cause an error ?

Thanks for your help and patience.

Answers


I would comment, but I don't think I have the ability to yet. But I concur with Marco, I am not experienced with this language or product, but I wonder, is the database on a remote machine? First try setting the server to the IP and seeing if that works.

I found this configuration online and removed a few things to get to the core

begin
  MyConnection1.LoginPrompt := false;
  MyConnection1.Username := 'test';
  MyConnection1.Password := 'test';
  MyConnection1.Database := 'test';
  MyConnection1.Server := '127.0.0.1';
  MyConnection1.Port := 3306;
  MyConnection1.Connect;
end;

One thing I noticed is it has a disable for the LoginPrompt, where as you don't, also it has a port. I would try setting the ip and port number, if that works, then try setting just the port number. If none of that works try the full implementation here and then go backwards in taking things out and setting server back to hostname

begin
  MyConnection1.Pooling := true;
  MyConnection1.PoolingOptions.MinPoolSize := 1;
  MyConnection1.LoginPrompt := false;
  MyConnection1.Options.Charset := 'utf8';
  MyConnection1.Options.Direct := true;
  MyConnection1.Options.UseUnicode := true;
  MyConnection1.Username := 'test';
  MyConnection1.Password := 'test';
  MyConnection1.Database := 'test';
  MyConnection1.Server := '127.0.0.1';
  MyConnection1.Port := 3306;
  MyConnection1.Connect;
end;

referenced from http://forums.devart.com/viewtopic.php?t=12035


Need Your Help

How to store Date from internet like "2014-12-01T20:00:00Z" in core data

core-data nsdate nspredicate nsdateformatter nstimeinterval

How to store Date from internet like "2014-12-01T20:00:00Z" in core data and compare this date with [NSDate Date] using nspredicate. as i am using @((date" >= startDate) && (date <= endD...

How to convert decimal value into integer

c#

I have a decimal value in a TextBox. I need to convert that value to an integer.