I need to connect 2 tables from 2 different servers.
How can I do that in C#?
This is what I have so far:
cmd = new MySqlCommand(String.Format("INSERT INTO {0} (a,b,c,d) SELECT (a,b,c,d) FROM {1}", ConfigSettings.ReadSetting("main_table"), ConfigSettings.ReadSetting("main_table")), con);
ConfigSettings.ReadSetting("main_table") for both of them is the same.
con.ConnectionString = ConfigurationManager.ConnectionStrings["con1"].ConnectionString;
con2.ConnectionString = ConfigurationManager.ConnectionStrings["con2"].ConnectionString
How to make this cmd to be workking with 2 different connection strings and with the same name for the table. Table name will change that’s why it is saved in config.
MySQLcannot dynamically link servers.If you want a direct copy between the databases, you would need to create a
FEDERATEDtable on the target server which would point to the source server, and just issue this command:on the target server.
If you have multiple source servers and / or tables, you should create a federated table for each of them.
The other option would be selecting all data from the source server onto the client (into an array, persistent recordset etc.), then insert data cached on the client into the table on the target server.