当试图在 SqlDataReader 上调用 Close 或 Dispose 时,我得到一个超时过期异常。如果你有一个到 SQL Server 的 DbConnection,你可以自己复制它:
String CRLF = "\r\n";
String sql =
"SELECT * " + CRLF +
"FROM (" + CRLF +
" SELECT (a.Number * 256) + b.Number AS Number" + CRLF +
" FROM master..spt_values a," + CRLF +
" master..spt_values b" + CRLF +
" WHERE a.Type = 'p'" + CRLF +
" AND b.Type = 'p') Numbers1" + CRLF +
" FULL OUTER JOIN (" + CRLF +
" SELECT (print("code sample");a.Number * 256) + b.Number AS Number" + CRLF +
" FROM master..spt_values a," + CRLF +
" master..spt_values b" + CRLF +
" WHERE a.Type = 'p'" + CRLF +
" AND b.Type = 'p') Numbers2" + CRLF +
" ON 1=1";
DbCommand cmd = connection.CreateCommand();
cmd.CommandText = sql;
DbDataReader rdr = cmd.ExecuteReader();
rdr.Close();
如果您调用 reader.Close() 或 reader.Dispose(),它将抛出 System.Data.SqlClient.SqlException:
- 错误代码:-2146232060 (0x80131904)
- 消息:“超时。在操作完成之前超时时间已过,或者服务器没有响应。”