I have a binary file with about 185k rows in it. C#
parses file in seconds. What would be the best way to update MSSQL
table with
Use SqlBulkCopy (to a temporary table) followed by MERGE.
The bulk-copy method can efficiently transfer data using a "push" from a .NET client. Using BULK INSERT requires a "pull" from the server (along with the required local-file access).
Then the MERGE
command (in SQL Server 2008+) can be used to insert/update/upsert the data from the temporary table to the target table according to the desired rules. Since the data is entirely in the database at this point, this operation will be as fast as can be. Using MERGE
may also result in performance advantages over many individual commands, even those within the same transaction.
See also:
I would try table-valued parameter:
http://www.codeproject.com/Articles/22392/SQL-Server-2008-Table-Valued-Parameters
Not sure you really want to do it via C#: probably want to use BULK INSERT and give it a file with your data properly formatted.