Приведённый код падает в выделенной строке
через некоторое время
с исключением TimeOut Expired
SqlConnection sqlConnection = new SqlConnection(
@"Data Source=EXTRAN\SQL_SERVER_2005;Initial Catalog=Garage;Integrated Security=False;Persist Security Info=True;User ID=sa;Password=2299296");
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand(
String.Format(@"SELECT Position.CarID, Position.TimeStamp, Position.X, Position.Y, Car.Number AS CarNumber, Model.Name AS ModelName,
ModelType.Name AS ModelTypeName, Position.State
FROM Position INNER JOIN Car
ON Position.CarID = Car.ID INNER JOIN Model
ON Car.ModelID = Model.ID INNER JOIN ModelType
ON Model.ModelTypeID = ModelType.ID
WHERE (Position.TimeStamp IN
(SELECT MAX(TimeStamp) AS MaxTimeStamp
FROM Position AS innerPosition
WHERE (@StartTime <= TimeStamp) AND (TimeStamp <= @FinishTime)
GROUP BY CarID)) AND (@StartTime <= TimeStamp) AND (TimeStamp <= @FinishTime)"), sqlConnection);
sqlCommand.Parameters.Add("@StartTime", typeof(DateTime));
sqlCommand.Parameters.Add("@FinishTime", typeof(DateTime));
sqlCommand.Parameters["@StartTime"].Value = DateTime.Today;
sqlCommand.Parameters["@FinishTime"].Value = DateTime.Now;
SqlDataReader reader = sqlCommand.ExecuteReader();
Тот же запрос отрабатывает в Sql Management Studio секунд за 5