title: Is this the only and good way to sync data between 2 databases programmatically
body: <p>I have 2 same databases.One in production and another in local.I'm trying to write c# windows service to sync data from time to time from production to local database.
  Here is a code snippet from my data sync service</p>
  
  <pre><code> private static bool StartDataSync(string tableName, string connectionStringLive, string connectionStringLocal,string databaseName)
      {
          bool status = false;
  
          DataSet dsResult = new DataSet();
  
          Int64 maxId = 0;
          MySqlConnection conLocal = new MySqlConnection(connectionStringLocal);
          MySqlCommand cmdLocal = new MySqlCommand("pr_GetMaxIdFromTable", conLocal);
          cmdLocal.CommandType = CommandType.StoredProcedure;
          MySqlParameter[] parameters = new MySqlParameter[4];
          parameters[0] = new MySqlParameter("vTableName", tableName);
          parameters[0].Direction = ParameterDirection.Input;
          parameters[1] = new MySqlParameter("vMaxId", MySqlType.BigInt);
          parameters[1].Direction = ParameterDirection.Output;
          parameters[2] = new MySqlParameter("vExist", "0");
          parameters[2].Direction = ParameterDirection.InputOutput;
          parameters[3] = new MySqlParameter("vDatabaseName", databaseName);
          parameters[3].Direction = ParameterDirection.Input;
  
          foreach (MySqlParameter param in parameters)
          {
              cmdLocal.Parameters.Add(param);
          }
  
          conLocal.Open();
          cmdLocal.ExecuteNonQuery();
          int ifExist = 0;
          ifExist = Convert.ToInt32(parameters[2].Value);
          if (ifExist == 1)
          {
  
              maxId = Convert.ToInt64(parameters[1].Value);
  
              MySqlConnection conLive = new MySqlConnection(connectionStringLive);
              MySqlCommand cmdLive = new MySqlCommand("Select * from " + tableName + " where Id&gt;" + maxId, conLive);
  
              MySqlDataAdapter adp = new MySqlDataAdapter(cmdLive);
              adp.Fill(dsResult);
  
  
  
              MySqlCommand cmdLocalInsert = null;
              string insertValues = string.Empty;
              foreach (DataRow dr in dsResult.Tables[0].Rows)
              {
                  insertValues = string.Empty;
                  foreach (DataColumn dc in dsResult.Tables[0].Columns)
                  {
                      insertValues = insertValues + Convert.ToString(dr[dc]) + ",";
                  }
                  insertValues = insertValues.Substring(0, insertValues.Length - 1);
                  cmdLocalInsert = new MySqlCommand("Insert into " + tableName + " Values(" + insertValues + ")", conLocal);
                  if (conLocal.State != ConnectionState.Open)
                  {
                      conLocal.Open();
                  }
                  cmdLocalInsert.ExecuteNonQuery();
              }
          }
  
          return status;
      }
  </code></pre>
  
  <p>I dont know if this is the only way of doing this or if this may cause any other issues in future.If any one can suggest any other method of doing this, it will be most appreciated.</p>