From a windows application I load data for offline processing. I do this using a SqlDataReader and bulkcopy. See code below
But one of my tables contains about 10.000 rows. When on the same network as the database server the proces takes about 2 seconds. Connected through a VPN Connection and a broadband router it takes about 70 seconds. This is due to latency in the network caused by the way the SqlDataReader delivers the result row by row.
Is there a faster way of retrieving the data than the SqlDataReader when there are many records.
public void bulkCopyTable(string getDataStoredProcedure, string destinationTable)
{
using (SqlConnection MasterConnection = new SqlConnection(MasterServerDbConnectionString))
{
MasterConnection.Open();
using (SqlConnection connection = new SqlConnection(localDbConnectionString))
{
connection.Open();
SqlCommand cmdMasterData = new SqlCommand(getDataStoredProcedure, MasterConnection);
cmdMasterData.CommandType = CommandType.StoredProcedure;
SqlParameter paramMasterData1 = new SqlParameter("@getAll", SqlDbType.Bit);
paramMasterData1.Value = 1;
cmdMasterData.Parameters.Add(paramMasterData1);
cmdMasterData.CommandTimeout = 60;
using (SqlDataReader dataReaderMasterData = cmdMasterData.ExecuteReader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(AutoProgConnection))
{
bulkCopy.DestinationTableName = destinationTable;
try
{
// Write from the source to the destination.
bulkCopy.WriteToServer(dataReaderMasterData);
}
catch (Exception ex)
{
...
}
}
}
}
}
}