2012-12-31 33 views
0

上發送錯誤與自定義模塊沒有數據我剛開始具有尚未開始發生直到昨晚我的自定義模塊,一個很奇怪的問題。基本上,當我嘗試請求爲模塊創建的自定義視圖時,前幾個頁面顯示正常,然後突然其餘的這些內容項目頁面超時,直到我回收應用程序池爲止。 (在瀏覽器中我得到一個324沒有數據發送錯誤)。在App_Data文件夾下的錯誤日誌中,我也沒有發現與此事件有關的錯誤。果園324只Web服務器

這裏是我會在事件查看器中的錯誤:

3005 
    An unhandled exception has occurred. 
    12/31/2012 12:03:17 PM 
    12/31/2012 5:03:17 PM 
    59d62d1f2da347caafd2dee71266126f 
    43 
    1 
    0 
    /LM/W3SVC/10/ROOT-2-130014459492939950 
    Full 
/
    E:\Inetpub\Test-Website\ 
    SERVERNAME 

    24756 
    w3wp.exe 
    NT AUTHORITY\NETWORK SERVICE 
    TimeoutException 
    Transaction Timeout 
    (the url was displayed here) 
    admin 
    True 
    Forms 
    NT AUTHORITY\NETWORK SERVICE 
    39 
    NT AUTHORITY\NETWORK SERVICE 
    False 

我沒有我的開發計算機上這個問題(上運行IIS或Visual Studio中的網站不再現問題)。

我幾乎正,所述模塊被設置以使每個連接被有效地處理。另外,考慮到自從網站上線以來(大約一個月)沒有發生這種情況,我猜測它與代碼無關。

下面是我如何設置服務類的實例:

namespace Example.Services 
{ 
    public interface IDocumentNoteService : ITransientDependency 
    { 
     List<DocumentNoteRecord> GetNotes(int? packageId, int noteTypeId); 
    } 

    public class DocumentNoteService : IDocumentNoteService 
    { 
     private readonly IRepository<DocumentNoteRecord> _docNoteRepo; 

     public DocumentNoteService(IRepository<DocumentNoteRecord> docNoteRepo) 
     { 
      _docNoteRepo = docNoteRepo; 
      Logger = NullLogger.Instance; 
      T = NullLocalizer.Instance; 
     } 

     public ILogger Logger { get; set; } 
     public Localizer T { get; set; }   

     public List<DocumentNoteRecord> GetNotes(int? packageId, int noteTypeId) 
     { 
       try { 
        var Notes = _docNoteRepo.Table.Where(x => x.Package_Id == packageId).Where(x => x.Note_Type_Id == noteTypeId).ToList(); 
        _docNoteRepo.Flush(); 
        return Notes; 
       } 
       catch (Exception ex) { 
        Logger.Error(ex, "There was a problem getting the document notes for this tour."); 
       } 
      return Enumerable.Empty<DocumentNoteRecord>().ToList<DocumentNoteRecord>(); 
     } 

    } 
} 

下面是部分驅動程序的代碼:

namespace ExampleCode.Drivers 
{ 
    public class TourPartDriver : ContentPartDriver<TourPart> { 
     private readonly ITourPartService _tourPartService; 
     private readonly ITourDateService _tourDateService; 
     private readonly IItinDetailService _tourItinDetailsService; 
     private readonly IExperiencesService _tourExpService; 
     private readonly ITourOptionService _tourOptionService; 
     private readonly IDestinationFactService _destinationFactService; 
     private readonly IDestinationFactManager _destinationFactManager; 
     private readonly IDocumentNoteService _documentNoteService; 
     private readonly IPackageUpgradesService _packageUpgradesService; 

     public TourPartDriver(
      ITourPartService tourService, 
      ITourDateService tourDateService, 
      IItinDetailService tourItinDetailsService, 
      IExperiencesService tourExpService, 
      ITourOptionService tourOptionService, 
      IDestinationFactService destinationFactService, 
      IDestinationFactManager destinationFactManager, 
      IDocumentNoteService documentNoteService, 
      IPackageUpgradesService packageUpgradesService 
      ) { 
      _tourPartService = tourService; 
      _tourDateService = tourDateService; 
      _tourItinDetailsService = tourItinDetailsService; 
      _tourExpService = tourExpService; 
      _tourOptionService = tourOptionService; 
      _destinationFactService = destinationFactService; 
      _destinationFactManager = destinationFactManager; 
      _documentNoteService = documentNoteService; 
      _packageUpgradesService = packageUpgradesService; 

      Logger = NullLogger.Instance; 
      T = NullLocalizer.Instance; 
     } 

     public ILogger Logger { get; set; } 
     public Localizer T { get; set; } 

     protected override DriverResult Display(
      TourPart part, string displayType, dynamic shapeHelper) { 
      return ContentShape("Parts_Tour",() => shapeHelper.Parts_Tour(
       TourID: part.tour_id, 
       TourName: part.tour_name, 
       PackageID: part.package_id, 
       Highlights: _tourExpService.GetTourExperiences(part.tour_id, part.package_id), 
       Description: part.description, 
       TourDates: _tourDateService.GetTourDatesDD(part.tour_id), 
       TourItinDetails: _tourItinDetailsService.GetItinDetails(part.package_id), 
       InitialTourOffsetDate: _tourDateService.GetInitialTourDateOffset(part.package_id), 
       TourOptions: _tourOptionService.GetInitialTourOptions(part.package_id), 
       TourPrice: _tourDateService.GetTourPrice(part.package_id), 
       TourNumDays: _tourItinDetailsService.GetTourNumDays(part.package_id), 
       TourNumMeals: _tourDateService.GetTourNumMeals(part.package_id), 
       DestinationFacts:_destinationFactManager.GetCategoryFacts(part.package_id), 
       PleaseNote: _documentNoteService.GetNotes(part.package_id, (int)NoteTypes.DocNoteType.PleaseNote), 
       WebRemarks: _documentNoteService.GetNotes(part.package_id, (int)NoteTypes.DocNoteType.WebRemarks), 
       Pace: _documentNoteService.GetNotes(part.package_id, (int)NoteTypes.DocNoteType.Pace), 
       PackageUpgrades: _packageUpgradesService.GetInitialPackageUpgrades(part.package_id) 
       ));    
     } 
    } 
} 

下面是視圖的代碼:

@{ 

List<DocumentNoteRecord> pleaseNote = Model.PleaseNote; 
List<DocumentNoteRecord> webRemarks = Model.WebRemarks; 
List<DocumentNoteRecord> pace = Model.Pace; 

if (pleaseNote.Count > 0) 
{ 
    <h4 class="tourSubTitle1">Please Note</h4> 
    foreach (var note in pleaseNote) { 
     <p>@Html.Raw(note.Note)</p> 
    } 
} 

if (webRemarks.Count > 0) { 
     <h4 class="tourSubTitle1">Web Remarks</h4> 
     foreach (var noteRemark in webRemarks) { 
      <p>@Html.Raw(noteRemark.Note)</p> 

     } 
    } 

if (pace.Count > 0) 
{ 
    <h4 class="tourSubTitle1">Pace</h4> 
    foreach (var notePace in pace) 
    { 
     <p>@Html.Raw(notePace.Note)</p> 
    } 
} 

}

任何幫助將不勝感激!我絕對是在這裏泡菜。

謝謝。

+0

你怎麼能「幾乎可以肯定的是,模塊設置,使每個連接有效地處置」?什麼是IDestinationFactService?這段代碼什麼時候運行? –

+0

它在查看特定內容項目時運行。這個服務類的唯一方法就是在那裏。該方法從部件驅動程序中調用,只是在視圖中顯示一些信息。 –

+0

從我讀過的內容來看,當你實現ITransientDependency,IDependency或ISingletonDependency時,事務應該被處理掉。 –

回答

0

切勿將記錄傳遞到視圖中。這樣做可以捕獲數據庫上下文,並可能導致連接泄漏或更糟。使用類似於視圖模型的純對象構建自己的形狀,並且不包含持久性實體。

+0

我修改了所有現有的代碼,以便不會將記錄傳遞到視圖中。我會繼續監視應用程序,看看是否遇到更多問題(這可能與服務器而不是Orchard有關),但似乎這已經緩解了這個問題。謝謝您的幫助。 –