SqlDataAdapter.Fill takes time more than CommandTimeout

别等时光非礼了梦想. 提交于 2019-12-24 09:26:34

问题


When I execute this query, though I set the ConnectionTimeOut to 1 second, SqlDataAdapter.Fill takes more time than 65 second. and timeout not work.

var cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * FROM [tblLargeData]";
con.Open();
cmd.Connection = con;

var ds = new DataSet();
var da = new SqlDataAdapter(cmd);
da.SelectCommand.CommandTimeout = 1;
da.Fill(ds);

tblLargeData is a table that contains large data in SQL server database. But when I change the query like this, CommandTimeOut work fine and timeout occur.

var cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * INTO #temp1 FROM [tblLargeData]; SELECT * FROM #temp1";
con.Open();
cmd.Connection = con;

var ds = new DataSet();
var da = new SqlDataAdapter(cmd);
da.SelectCommand.CommandTimeout = 1;
da.Fill(ds);

In CommandText first insert result in a temp table and then select from it as result.

Why CommandTimeout not work in first query?

来源:https://stackoverflow.com/questions/38418865/sqldataadapter-fill-takes-time-more-than-commandtimeout

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