Possibly a duplicate of this. I'm trying to retrieve data from BigQuery and trying to insert it into SQL Server. I am able to retrieve data from BigQuery relatively easily. But the problem is, despite the following code (inspired from the duplicate question), even with 100K rows its taking 97+ seconds to insert that data into SQL Server!
using( var conn = new SqlConnection( dbConnString ) )
{
conn.Open();
try
{
using( var sqlBulkCopy = new SqlBulkCopy( conn, SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.UseInternalTransaction, null ) )
{
sqlBulkCopy.BulkCopyTimeout = 100;
sqlBulkCopy.DestinationTableName = table.TableName;
sw.Start(); //StopWatch
sqlBulkCopy.WriteToServer( table );
}
sw.Stop();
Console.WriteLine( $"Time taken to INSERT data: {sw.ElapsedMilliseconds}" );
}
catch( Exception ex )
{
Console.WriteLine( $"Error while inserting in to DB: {ex.Message}" );
}
}