I have a program that is reading through a text file to update/insert rows. I've tried the following pseudocode methods below. These are all extremely slow. I'm running this code directly on the SQL Server itself and these processes all take many hours to complete...
The amount of update/insert statements is somewhere in the millions. What is the most efficient way to run that many SQL statements in .net c#?
// Insert/Update while reading text file
While (reader.read)
{
sql.ExecuteNonQuery();
}
Or...
// build a list to loop through later and insert/update
While (reader.read)
{
List.Add(sql);
}
foreach(string s in sql)
{
sql.ExecuteNonQuery();
}
Or...
// Build a list and run 1000 statements at one time
While (reader.read)
{
List.Add(sql);
if(List.Count == 1000)
{
sql.ExecuteNonQuery();
}
}