title: Synchronize SQL Server table and Postgres table
body: <p>There is SQL Server database table which is source and Postgres database as destination table. Is there any efficient approach using C# to keep same data on postgres table side reflecting sql server table? </p>
  
  <p>What i tried so far is to use both <code>System.Data</code> and <code>Npgsql</code>. My idea was to delete every time data in destination table and bulk all data to it from source table. There is nice <code>SqlBulkCopy</code> but comming from <code>System.Data</code>, i do not see same in <code>Npgsql</code>. Could anyone help me out with this?</p>
  
  <pre><code>private static void PerformBulkCopy()
          {
              string SourcedestconnectionString = @"";
              string TarettargconnectionString = @"";
              // get the source data
              using (SqlConnection sourceConnection = new SqlConnection(SourcedestconnectionString))
              {
                  SqlCommand myCommand = new SqlCommand("SELECT * FROM [pub].[vw_Services_NDPEWork]", sourceConnection);
                  sourceConnection.Open();
                  SqlDataReader reader = myCommand.ExecuteReader();
  
                  // open the destination data
                  using (NpgsqlConnection destinationConnection = new NpgsqlConnection(TarettargconnectionString))
                  {
                      // open the connection
                      destinationConnection.Open();
  
                      using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection.ConnectionString))
                      {
                          bulkCopy.BatchSize = 500;
                          bulkCopy.NotifyAfter = 1000;
                          bulkCopy.SqlRowsCopied += new SqlRowsCopiedEventHandler(Target);
                          bulkCopy.DestinationTableName = "roberttest";
                          bulkCopy.WriteToServer(reader);
                      }
                  }
                  reader.Close();
              }
          }
  </code></pre>