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 email@example.com'(useing passworkd: YES)'.
Why will the code method cause an error ?
Thanks for your help and patience.
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