I don't have any idea why SqlBulkCopy does not insert all of the records from the reader. Code:
using (OleDbDataReader dr1 = cmd.ExecuteReader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(ss, SqlBulkCopyOptions.TableLock, null))
{
bulkCopy.BulkCopyTimeout = 0;
bulkCopy.BatchSize = 500;
bulkCopy.DestinationTableName = tableName;
try
{
bulkCopy.WriteToServer(dr1);
}
catch (Exception ex)
{
Log.LogSystemLog(ex.ToString());
return false;
}
}
GC.Collect();
dr1.Close();
}
I want to bulkCopy about 300k records. It works when I'm running this from localhost to the same database, but when I run this from the server - it always inserts ~7k records... and no error, or exception. On the server 4GB free RAM are available. On localhost ~ 1,5GB.
I have no idea why it's working properly on localhost, but on the server it is not.