I have a source database in one system. I want to create a target Database (with same schema as Source database) in another system in a different network (both systems are not connected in any way).
now we are creating a dump on system 1 and using a stick to copy it into system 2. But we are looking for a better solution through C#.
I have already created sqldump on system 1 and now I need help on how I can access the system 2 from system 1 to use the dump file and create a target database or should I be writing a code to be run in system 2 that in turn takes the dump of system1 database? how should I be going about with this?
I will go on further to do some database verification once the Target db is created, comparing the 2 databases and syncing the data among the two.
So I am looking for a C# solution.
any ideas?
P.S. code that creates sqldump on system 1:string constring1 = "SERVER=localhost;" + "DATABASE=;" + "UID=root;" + "PASSWORD=;" + "Convert Zero Datetime=True;" +
"Allow Zero Datetime=True";
using (MySqlConnection conn = new MySqlConnection(constring1))
{
using (MySqlCommand cmd = new MySqlCommand())
{
using (MySqlBackup mb = new MySqlBackup(cmd))
{
cmd.Connection = conn;
conn.Open();
mb.ExportInfo.AddCreateDatabase = true;
mb.ExportInfo.ExportTableStructure = true;
mb.ExportInfo.ExportRows = false;
mb.ExportToFile(file1);
}
}
}
解决方案
Option 1: By using web services.
Create a web server and host a web service at server 2.
Server 1 will send over the byte[] (byte array) to server 2 through the web service.
Option 2: By using a web page
At server 2, create a ASP.NET web page that accept a http post.
Server 1 will access the web page programmatically and upload the file.
Server 2, once the file received at the web page, ASP.NET engine will process it.
Option 3: By opening a TCP Client/Server port using C# at server 2
Create a C# Socket at server 2.
Server 1 will connect the socket then transmit the byte[] to server 2 through the socket.