1

在此項目中,我使用了MVC-3,其中包含輸出緩存屬性以及web.config中的相應引用,以及希望的global.asax(如下所示)。我從共享主機運行生產,並且無法運行aspnet_regsql作爲管理員來創建適當的對象,因此我複製了AspNet_SqlCacheTablesForChangeNotification表SP,並從我的開發箱中觸發以設置數據庫。已刪除或未創建SQLServer OutputCache對象

一般來說,一切都很好,但我發現大約每2或3天一次所有的緩存數據庫對象都被刪除,並且不會在應用程序啓動時重新創建。 (沒有託管co腳本正在刪除它們)。

爲了讓網站再次運行,我最終手動複製了數據庫對象。

如何刪除對象,或者讓它們自動創建?

在Global.asax我的應用程序開始看起來是這樣的:

protected void Application_Start() 
{ 
    RegisterGlobalFilters(GlobalFilters.Filters); 

    SqlCacheDependencyAdmin.EnableNotifications(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString); 
    SqlCacheDependencyAdmin.EnableTableForNotifications(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString, "be_Posts"); 
    SqlCacheDependencyAdmin.EnableTableForNotifications(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString, "be_PostTag"); 

    SiteMap.Provider.SiteMapResolve += new SiteMapResolveEventHandler(SiteMapPathExpansionResolver.OnSiteMapResolve); 
    RegisterRoutes(RouteTable.Routes); 
} 

和我的應用程序結束看起來是這樣的:

protected void Application_End() 
    { 
     SqlCacheDependencyAdmin.DisableTableForNotifications(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString, "be_Posts"); 
     SqlCacheDependencyAdmin.DisableTableForNotifications(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString, "be_PostTag"); 
     SqlCacheDependencyAdmin.DisableNotifications(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString); 
    } 

的web.config條目看起來是這樣的:

<caching> 
    <sqlCacheDependency enabled="true" pollTime="10000" > 
    <databases> 
     <add name=" db" 
     connectionStringName="ApplicationServices" 
     pollTime="10000" 
     /> 
    </databases> 
    </sqlCacheDependency> 
</caching> 

回答

0

所以我通過評論/去除Application_End中的禁用來有效地解決了這個問題。我讀過,這使得sql服務器打開句柄,但我沒有找到任何其他解決方案的工作。我嘗試添加創建觸發器和啓動事件來重新創建表等等以及其他一些方法,但只是刪除禁用似乎工作。

我希望我所在的共享和數據庫服務器沒有問題,但託管公司沒有向我抱怨,我真的沒有辦法知道這種方法是否會導致併發症,因爲他們不授予對這種監控的訪問權限。