2014-08-31 112 views
0

我使用本地數據庫在本地構建了ASP.NET MVC5網站。我明白了這一點,我希望將它引入到Azure Web服務中,因此我啓用了Azure網站並設置爲從Visual Studio Online Git庫中進行部署。部署發生,但訪問頁面僅生成'處理請求時發生錯誤'。錯誤。將Azure MVC5網站部署到Azure,獲得500個內部服務器錯誤

如果我看看日誌中我得到列出以下錯誤:

  1. MODULE_SET_RESPONSE_ERROR_STATUS

Warning ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully. (0x0)", ConfigExceptionInfo=""

數據庫連接字符串已被替換爲AzureSqlDatabase連接字符串,所以我試圖檢查那裏。該字符串'看起來'很好,但我注意到,當我在調試模式下運行應用程序時,它以某種方式使用原始本地Sql數據庫,儘管該連接字符串不再在代碼中!

我已經嘗試了SO中列出的一些建議,包括啓用詳細日誌記錄和重新推送web.config文件,但似乎沒有任何工作。關於如何追蹤和解決此問題的任何想法?

編輯: 隨着MFanto的幫助,我發現應用程序仍然使用舊的本地SQL數據庫的連接字符串。 (數據源= \ SQLEXPRESS;初始目錄= HouseOfBurt.Models.DataContext;集成安全性= TRUE; MultipleActiveResultSets =真)

在Web.config如下:

<?xml version="1.0"?> 

<configuration> 
    <configSections> 
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> 
     <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> 
    </sectionGroup> 
    </configSections> 

    <system.web.webPages.razor> 
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <pages pageBaseType="System.Web.Mvc.WebViewPage"> 
     <namespaces> 
     <add namespace="System.Web.Mvc" /> 
     <add namespace="System.Web.Mvc.Ajax" /> 
     <add namespace="System.Web.Mvc.Html" /> 
     <add namespace="System.Web.Optimization"/> 
     <add namespace="System.Web.Routing" /> 
     <add namespace="Application" /> 
     <add namespace="Application.Models" /> 
     </namespaces> 
    </pages> 
    </system.web.webPages.razor> 

    <appSettings> 
    <add key="webpages:Enabled" value="false" /> 
    </appSettings> 

    <system.webServer> 
    <handlers> 
     <remove name="BlockViewHandler"/> 
     <add name="BlockViewHandler" path="*.cshtml" verb="*" 
      preCondition="integratedMode" 
      type="System.Web.HttpNotFoundHandler" /> 
    </handlers> 
    </system.webServer> 
</configuration> 

的Web.Debug。配置Config(密碼改性當然)

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <!-- 
    In the example below, the "SetAttributes" transform will change the value of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an attribute "name" that has a value of "MyDB". 

    <connectionStrings> 
     <add name="MyDB" 
     connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
     xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> 
    </connectionStrings> 
    --> 
    <connectionStrings> 
    <add name ="DataContextContainer" connectionString="Server=tcp:r0c0umg8th.database.windows.net,1433;Database=HouseOfBurt;User [email protected];Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.EntityClient"/> 
    </connectionStrings> 

    <system.web> 
    <compilation xdt:Transform="RemoveAttributes(debug)" /> 
    <!-- 
     In the example below, the "Replace" transform will replace the entire 
     <customErrors> section of your Web.config file. 
     Note that because there is only one customErrors section under the 
     <system.web> node, there is no need to use the "xdt:Locator" attribute. 

     <customErrors defaultRedirect="GenericError.htm" 
     mode="RemoteOnly" xdt:Transform="Replace"> 
     <error statusCode="500" redirect="InternalError.htm"/> 
     </customErrors> 
    --> 
    </system.web> 
</configuration> 

EDIT2:所述的DbContext類的添加:

public class DataContext : DbContext 
    { 
     #region Tables 

     public DbSet<Article> Articles { get; set; } 
     public DbSet<Category> Categories { get; set; } 
     public DbSet<Link> Links { get; set; } 

     #endregion Tables 

     #region Public Methods 

     #endregion Public Methods 

    } 
+1

如何更換連接字符串?通過門戶上的Azure網站設置,還是使用web.config轉換(例如web.debug.config和web.release.config)?您是否嘗試過遠程調試天藍色網站以查看其中斷的位置? – mfanto 2014-08-31 16:23:42

+0

我改變了實際的web.Config。我會看看我是否可以進行遠程會話。 – ChargerIIC 2014-08-31 19:54:15

+0

無法獲取調試會話進行連接,但確實報告了SqlException。 web.config,web.debug.config和web.release.config都具有指向實體框架的相同連接字符串。儘管本地調試仍然連接到本地SQL實例,所以我做錯了什麼。任何想法是什麼? – ChargerIIC 2014-08-31 23:38:58

回答

4

您的DbContext您發佈的類別名爲DataContext,但示例中的連接字符串爲DataContextContainer

如果未明確提供連接字符串,實體框架將查找名稱與完全匹配的連接字符串到DBContext的名稱;其他約定將嘗試使用基於代碼的連接字符串,目標爲SQLExpress。

更改連接字符串名稱似乎已解決問題。

有關實體框架連接字符串約定的更多信息可在http://msdn.microsoft.com/en-us/data/jj592674找到。