"Streaming"从SQL Server中的表中读取超过1000万行

Ram*_*dar 4 c# sql-server sql-server-2012

以流方式(如SQL Server Management Studio)从表(在SQL Server 2012,BI实例中)读取数百万条记录的最佳策略是什么?

我需要在本地缓存这些记录(C#控制台应用程序)以进行进一步处理.

更新 - 与SqlDataReader一起使用的示例代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Threading;


namespace ReadMillionsOfRows
{
    class Program
    {
        static ManualResetEvent done = new ManualResetEvent(false);


        static void Main(string[] args)
        {

          Process();
          done.WaitOne();
        }

        public static async Task Process()
        {
            string connString = @"Server=;Database=;User Id=;Password=;Asynchronous Processing=True";
            string sql = "Select * from tab_abc";

            using (SqlConnection conn = new SqlConnection(connString))
            {
                await conn.OpenAsync();
                using (SqlCommand comm = new SqlCommand(sql))
                {
                    comm.Connection = conn;
                    comm.CommandType = CommandType.Text;

                    using (SqlDataReader reader = await comm.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            //process it here
                        }
                    }
                }
            }

            done.Set();
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

awr*_*t18 7

使用SqlDataReader它只是前进和快速.它只会在读取记录范围时保留对记录的引用.