Bulk upload strategy for SQL server

后端 未结 2 692
青春惊慌失措
青春惊慌失措 2021-01-29 05:18

I am uploading data from CSV to SQL table using the following function.

Is there a better way to do it?

I am concerned about , right now, connection hold for lon

2条回答
  •  猫巷女王i
    2021-01-29 05:48

    Your best bet here is probably SqlBulkCopy, which throws raw TDS at the server very efficiently. SqlBulkCopy takes two types of input:

    • DataTable
    • IDataReader

    So at that point you have 3 options:

    • transform your List to a DataTable manually
    • use something like FastMember to obtain an IDataReader over your existing list (an example of this is at the bottom of the project page: https://github.com/mgravell/fast-member) - on nuget: https://www.nuget.org/packages/FastMember/
    • ditch your existing list, and read the CSV directly as an IDataReader - there is a "LumenWorks" CsvReader that has always worked well for that; the closest nuget link I can see is https://www.nuget.org/packages/LumenWorksCsvReader/ (although this isn't the original, it has been extended)

提交回复
热议问题