Database name at runtime

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
fcpr
Posts: 2
Joined: Tue 13 Dec 2011 18:24

Database name at runtime

Post by fcpr » Tue 13 Dec 2011 18:43

Hi,

I created a database and it will be deployed with a windows service in diferent computers. Is there a way to create (register) the database at run time in order to set TMYConnection.Database property with this value?
I don't want to use (I can't because it's a windows service) the TMyConnectDialog.

Thanks,

Francisco

AndreyZ

Post by AndreyZ » Wed 14 Dec 2011 09:38

Hello,

MySQL doesn't allow creating a new database without connecting to an existent database. You should connect to the mysql system database (it always exists) before creating your own database and create your new database afterwards. After this you can connect to your new database. Here is a code example:

Code: Select all

MyConnection.Database := 'mysql';
MyConnection.Open;
MyConnection.ExecSQL('CREATE DATABASE ...', []);
MyConnection.Database := 'new_database_name';
MyConnection.Open;

Post Reply