1

I have a problem which I couldn't solve for two days. Here is the story.
I am fetching a list of records from my MySQL 5.0 database using LINQ to SQL, but the execution will break with an exception saying:

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

I am using entity frame work code first at my back end. Here is my code:

context = new NebeContext();
var data2 = (from row in context.PollingStationConstituencyCandidates
    where row.ElectionId.Equals(electionId) && row.ConstituencyId.Equals(constituencyId)
    select new { row.LocationId, row.LocationNameA, row.PollingStationNameA, row.PollingStationNameE, row.PollingStationId }).Distinct();

List<PollingStationInfo> resultList = new List<PollingStationInfo>();
PollingStationInfo result = new PollingStationInfo();
foreach (var i in data2)
{
    result = new PollingStationInfo() { LocationId = i.LocationId, LocationNameA = i.LocationNameA, NameA = i.PollingStationNameA, NameE = i.PollingStationNameE, PollingStationId = i.PollingStationId };
    resultList.Add(result);
}
return resultList;
4

1 に答える 1

1

エラーメッセージは自明です。クエリがデータベースの完了に時間がかかりすぎて、タイムアウトが発生します...

また:

SQLのプロファイルを作成し、追加のインデックスまたはより適切なクエリが必要かどうかを確認します。また、n+1クエリを取得しないことを確認してください

また

データコンテキストでタイムアウトを変更する

于 2012-04-18T19:13:22.847 に答える