问题
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