Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Fastest way to import fixed len file into sql table

Fastest way to import fixed len file into sql table

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasequestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    byka
    wrote on last edited by
    #1

    what's the fastest way to import fixed len file into sql table? File is about 5 mil records

    P S M A 4 Replies Last reply
    0
    • B byka

      what's the fastest way to import fixed len file into sql table? File is about 5 mil records

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Use a bulk loader. Most database engines provide a dedicated program to do this.

      I was brought up to respect my elders. I don't respect many people nowadays.
      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      B 1 Reply Last reply
      0
      • P Pete OHanlon

        Use a bulk loader. Most database engines provide a dedicated program to do this.

        I was brought up to respect my elders. I don't respect many people nowadays.
        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        B Offline
        B Offline
        byka
        wrote on last edited by
        #3

        can I call sql builk insert from .net?

        P 1 Reply Last reply
        0
        • B byka

          can I call sql builk insert from .net?

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Yes.

          I was brought up to respect my elders. I don't respect many people nowadays.
          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          1 Reply Last reply
          0
          • B byka

            what's the fastest way to import fixed len file into sql table? File is about 5 mil records

            S Offline
            S Offline
            Simon_Whale
            wrote on last edited by
            #5

            Have a read of this, assuming it's SQL Server BULK INSERT (Transact-SQL)[^]

            Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

            1 Reply Last reply
            0
            • B byka

              what's the fastest way to import fixed len file into sql table? File is about 5 mil records

              M Offline
              M Offline
              Mike E Andrews
              wrote on last edited by
              #6

              As other responders have said, use the System.Data.SqlClient.SqlBulkCopy class. Also, implement your own IDataReader in a class to read the file. The SqlBulkCopy contains a method called WriteToServer which has an overload that takes an IDataReader. Once this is done, you can simply create an IDataReader using a TextReader (via the class you made) and now you can simply read a row and write the row without using a lot of memory with DataTable or DataSet objects.

              1 Reply Last reply
              0
              • B byka

                what's the fastest way to import fixed len file into sql table? File is about 5 mil records

                A Offline
                A Offline
                AmitGajjar
                wrote on last edited by
                #7

                Hi, You have not mention is that one time or you have text feed in one folder. Anyway, You can create one SSIS package that can import your file data into sql server. you can schedule your SSIS package if that file is frequently updating. even you can execute package from your Code behind. you can also use bulk insert as other suggested.

                Thanks -Amit Gajjar (MinterProject)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups