mysql - Setting "Server" programatically with a TFDConnection -
tfdconnection.params.server not valid published property in delphi xe7. how can set server location programatically? have 2 mysql servers (test , production) @ different ip's , based on doing in application, want switch , forth between 2 servers.
please read documentation, tells how define firedac connection mysql:
connect mysql server (firedac)
you specify db server part of connection definition:
connection definitions can defined in external .ini file, can reference in tfdmanager.connectiondeffilename
property, or load dynamically using tfdmanager.loadconnectiondeffile()
method.
[mysql_connection_1] driverid=mysql server=192.168.1.100 ... [mysql_connection_2] driverid=mysql server=192.168.1.101 ...
or dynamically using tfdmanager.connectiondefs
property:
var odef: ifdstanconnectiondef; begin odef := fdmanager.connectiondefs.addconnectiondef; odef.name := 'mysql_connection_1'; odef.driverid := 'mysql'; odef.server := '192.168.1.100'; ... odef.apply; odef := fdmanager.connectiondefs.addconnectiondef; odef.name := 'mysql_connection_2'; odef.driverid := 'mysql'; odef.server := '192.168.1.101'; ... odef.apply;
var oparams: tstrings; begin oparams := tstringlist.create; oparams.add('server=192.168.1.100'); ... fdmanager.addconnectiondef('mysql_connection_1', 'mysql', oparams); oparams.clear; oparams.add('server=192.168.1.101'); ... fdmanager.addconnectiondef('mysql_connection_2', 'mysql', oparams);
either way, can tell tfdconnection
connection definition use reach each database when needed:
fdconnection1.connectiondefname := 'mysql_connection_1'; // or: fdconnection1.connectiondefname := 'mysql_connection_2'; fdconnection1.connected := true;
alternatively, can specify connection parameters directly in tfdconnection.params
property if not want pre-define separate connection definitions:
fdconnection1.drivername := 'mysql'; fdconnection1.params.clear; fdconnection1.params.add('server=192.168.1.100'); // or: fdconnection1.params.values['server'] := '192.168.1.100'; ... fdconnection1.connected := true;
Comments
Post a Comment