SQL DataReader network usage limit

一世执手 提交于 2021-02-08 19:43:49

问题


I have such an idea (don't know bad or good). I have utility, which connects by reglament to SQL server and fetches some data to application. Data is simple (2 varchar text attributes), but count of data is ~ 3 millions rows. So, my application uses network very intensively. Can I programmatically decrease (limit, throttling, etc...) the network bandwidth usage by SQL DataReader? Let it work more slowly, but not stress nither server nor client. Is this idea good? If not, what I have to do so?

Here is code, so far:

using (SqlConnection con = new SqlConnection("My connection string here"))
{
    con.Open();
    using (SqlCommand command = new SqlCommand(query, con))
    {                        
        using (SqlDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                yield return new MyDBObject()
                {                               
                    Date = (DateTime)reader["close_date"],                                
                    JsonResult = (string)reader["json_result"]
                };
            }
        }
    }
}

回答1:


Making the server buffer data or hold an open query longer could actually be significantly increasing load on the server, but ultimately the only way to do what you're after would be to apply "paging" to your query, and access the data in successive pages, perhaps with pauses between pages. The pages could still be pretty big - 100k for example. You can achieve this relatively easily with OFFSET/FETCH in SQL Server.



来源:https://stackoverflow.com/questions/47411338/sql-datareader-network-usage-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!