How do I read a large file from disk to database without running out of memory

后端 未结 6 894
野性不改
野性不改 2021-01-13 14:53

I feel embarrassed to ask this question as I feel like I should already know. However, given I don\'t....I want to know how to read large files from disk to a database witho

6条回答
  •  我在风中等你
    2021-01-13 15:41

    Actually your code is reading all data from file and keep into TextReader(in memory). Then you read data from TextReader to Save server.

    If data is so big, data size in TextReader caused out of memory. Please try this way.

    1) Read data (each line) from File.

    2) Then insert each line to Server.

    Out of memory problem will be solved because only each record in memory while processing.

    Pseudo code

    begin tran
    
    While (data = FilerReader.ReadLine())
    {
      insert into Table[col0,col1,etc] values (data[0], data[1], etc)
    }
    
    end tran
    

提交回复
热议问题