1

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.

Marco
  • 56,740
  • 14
  • 129
  • 152
grant1842
  • 357
  • 1
  • 7
  • 23
  • I don't know MyDAC, but IMHO the `@00.00.00.00` in the error message indicates you are trying to connect to host with IP `00.00.00.00`, so I would say you are missing provider. – TLama May 08 '12 at 02:50
  • @Marco Thanks for your comments. Its a weird problem. I tried the IP as well as the host name. but not working in code. – grant1842 May 08 '12 at 03:19
  • Wasn't the error class *EMySqlException*? Please edit if need be. – menjaraz May 08 '12 at 03:59
  • What connection component do you use: `TMyConnection` or `TMyEmbConnection`? – menjaraz May 08 '12 at 04:07
  • 1
    If the connection from component on your form works and doesn't from your code, simply get the needed properties with their values from the component. Drop one on your form, configure it, so you are able to connect and over your form designer press ALT + F12. It will show you the form source, where just find the connection component by it's name and see what properties are stored. It should be just the necessary minimum needed to component to connect properly. – TLama May 08 '12 at 09:44
  • I think you have same problem as this post: http://stackoverflow.com/q/8711495/723693 – ain May 08 '12 at 09:58
  • @TLama THis wroked great . I do not understand why this component is so fussy.But the alt + F12 and copy and paste worked great. – grant1842 May 08 '12 at 21:52
  • Glad it helped ;-) Actually, I'm using this *trick* for a long time for such kind of components. It might ensure you that what you set (on the form at design time) is what you get (at runtime when you copy & paste it), without any mistake. – TLama May 08 '12 at 22:01

1 Answers1

2

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

Dennis
  • 338
  • 3
  • 12
  • Thanks for the comments. I tried the full implantation and no go . It is weard i can put the info in the object inspector and it works . – grant1842 May 08 '12 at 03:14
  • No problem, I hope something works, please let me know if it did or didn't – Dennis May 08 '12 at 03:15
  • If 'loginprompt' is true, then a dialog box will appear, asking the user for username and password; if these are being passed directly in the connection, then 'loginprompt' should be set to false. This field allows multiple users to connect to the database. – No'am Newman May 08 '12 at 03:16
  • You used the ip of the database and the port? try removing the pooling stuff and the Options.* Are you still getting the same error too? – Dennis May 08 '12 at 03:20
  • I figured the loginprompt would prompt with a dialog box, which is not what he is looking for if he is setting the username and password in the connection – Dennis May 08 '12 at 03:20
  • I was doing a google search on that error, it could be the database is not configured quite right, even if you are allowed to login directly or through some other means, I would focus on the MySql error and look for remedies to that, your app may be configured just fine, Good Luck and let me know if you get it working! – Dennis May 08 '12 at 03:31