在本地开发机器上,当通过网站(ASP.NET - ADO.NET)运行时,我的查询无限期超时。昨天运行的相同查询很好。当我从本地机器执行它时它运行良好。
我什至求助于重新启动机器。会是什么?
每个请求的说明:
默认 30 秒后查询超时(在 ADO.NET 中)。如果我将它设置为 0(无限期) - 它会无限期地运行。在查询分析器中它立即运行(1 秒)
查询没有改变。这是查看代码:
.
public static List<Shipment> GetShipments(List<string> customerIds, DateTime dateFrom, DateTime dateTo)
{
try
{
var data = new List<Shipment>();
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
const string SQL = @"
SELECT TOP 1000 SH.ShipmentId, SH.TripId, CASE IsCancelled WHEN 1 THEN 'X' ELSE SH.Status END Status,
SH.FromMunicipality, SH.FromAdministrativeArea,
SH.ToMunicipality, SH.ToAdministrativeArea,
SH.PONumber, SH.ProCodeId, SH.ShipperReferenceNumber, SH.BOLNumber,
T.ScheduledPickupDate, T.ScheduledDeliveryDate,
CASE WHEN NOT TN.PDFBinary IS NULL THEN 1 ELSE 0 END HasPOD
FROM dbo.vPcyShipment SH
INNER JOIN dbo.vPcyTrip T ON SH.TripId = T.TripId
LEFT OUTER JOIN dbo.tTripNumber TN ON SH.TripId = TN.TripNumber
WHERE SH.CustomerId IN ({0})
AND T.ScheduledPickupDate BETWEEN @DateFrom AND @DateTo
ORDER BY T.ScheduledPickupDate DESC";
var customerParamNames = customerIds.Select((s, i) => "@customer" + i.ToString(CultureInfo.InvariantCulture)).ToArray();
var customerInClause = string.Join(",", customerParamNames);
using (var command = new SqlCommand(string.Format(SQL, customerInClause), connection))
{
command.Parameters.AddWithValue("@DateFrom", dateFrom);
command.Parameters.AddWithValue("@DateTo", dateTo);
for (var i = 0; i < customerParamNames.Length; i++)
{
command.Parameters.AddWithValue(customerParamNames[i], customerIds[i]);
}
using (var dataTable = new DataTable())
{
dataTable.Load(command.ExecuteReader());
var query = from row in dataTable.AsEnumerable()
select new Shipment
{
ShipmentId = row.Field<string>("ShipmentId"),
TripId = row.Field<string>("TripId"),
PoNo = row.Field<string>("PONumber"),
ProCodeId = row.Field<string>("ProCodeId"),
ShipperRef = row.Field<string>("ShipperReferenceNumber"),
BolNo = row.Field<string>("BOLNumber"),
ProphecyStatusCode = row.Field<string>("Status"),
FromCity = row.Field<string>("FromMunicipality"),
FromState = row.Field<string>"FromAdministrativeArea"),
ToCity = row.Field<string>("ToMunicipality"),
ToState = row.Field<string>("ToAdministrativeArea"),
ScheduledPickup = row.Field<DateTime>("ScheduledPickupDate"),
ScheduledDelivery = row.Field<DateTime>("ScheduledDeliveryDate"),
HasPOD = row.Field<int>("HasPOD")
};
data.AddRange(query.ToList());
}
}
}
return data;
}
catch (Exception ex)
{
Log(ex);
}
return null;
}