I have a customer that wants to import his sub-customers pricetools (more that 2.000.000 records) every day into a SQL Server database (and yeah....there are more than 900.000 rows of changes every day).
The data is provided in CSV format (not in RFC-4180 standard ç_ç, but nvm) and can be an Insert, Delete or Update of data.
My problem is that the insert of the data inside the database take more than 1 night to end and I need to speed it up.
What I'm doing at the moment is:
- Cast the csv file into a Datatable (Tab1) (~3 minutes)
- Select all data inside the previous table (Tab0) and match them with the Tab1 (~15 minutes, the unchanged rows are flagged as unmodified, so they are ignored in the
adapter.Update
, I check that thing for the first rows and seems that it works, I usedataRowToProcess.AcceptChanges()
to achieve that). Launch the following command to apply the changes (More than 5 hours for 900.000 changes):
cmdSQL = New SqlCommand(superQuery, cn) Dim adapter As SqlDataAdapter = New SqlDataAdapter(cmdSQL) adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey Dim build As SqlCommandBuilder = New SqlCommandBuilder(adapter) build.SetAllValues = False adapter.Update(dataTableCustomersDetail) 'Insert/Update records
If I have many inserts the process, it is slower than the same amount of updates.
What am I doing wrong? Am I missing some SqlDataAdapter
option?
Thanks