Page 1 of 1

Database name at runtime

Posted: Tue 13 Dec 2011 18:43
by fcpr
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

Posted: Wed 14 Dec 2011 09:38
by AndreyZ
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;