So, I have to import CSV file (up to 500mb of size) in ASP.NET Core 2.1 to MS sql database.
For importing I am using Sql Bulk insert, everything it's okay, but some of uploads take about 20 minutes. Even though those requests with import will be rare. But still thinking how to make it more better using CallBack, so when I start import I return response and in the background thread will be active task who will willing to get success information of finished import.
What do you think if it's worth or maybe there is a better solution?
public async Task AddBulk<T>(IDataReader data) where T : class, new()
{
if (Connection.State == ConnectionState.Broken || Connection.State == ConnectionState.Closed)
{
await Connection.OpenAsync();
}
using (SqlBulkCopy bulk = new SqlBulkCopy(Connection))
{
bulk.DestinationTableName = "Test_Data_Table";
bulk.BatchSize = 5000;
bulk.EnableStreaming = true;
bulk.WriteToServer(data);
data.Close();
}
}