I have 2 tables one is in local database and other one is on remote server.
I use port forwarding in C# to get my ssh remote connection to the localhost:3306 my local database is on localhost:3307
How can I copy one table to another one if they are both on localhost but with different ports.
This is my query that I want to do:
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);
Both tables have same columns and that is why I am using only one input from config settings.
But I have 2 connections strings as they are on different ports.
con.ConnectionString = ConfigurationManager.ConnectionStrings["con1"].ConnectionString;
con2.ConnectionString = ConfigurationManager.ConnectionStrings["con2"].ConnectionString
Is there any way to get my query to work with those 2 ports as I don’t want to be using FEDERATED connection in MySql. There must be the way as they are both on the same server.
Thank you
EDIT:
Connection strings:
<add name="Con2" connectionString="server=localhost;port=3307;user id=root;Password=*****;database=data" providerName="MySql.Data.MySqlClient"/>
<add name="Con1" connectionString="server=localhost;port=3306;user id=root;Password=******;database=data" providerName="MySql.Data.MySqlClient"/>
Pseudocode to move data between two separate tables on two different connection
first row
Save the second datatable
Please note that this has not been tested. Take it as experimental.
EDIT: Seeing the comments I will add another way to update the second table
This is in the case you don’t need to insert a whole record from the dtSource in the destination table. In this case I revert to an INSERT command with parameters, loop on the source table, insert in the destination table