title: Elmah.Mvc not logging in MVC4 app when deployed onto Azure
body: <p>I'm experiencing an issue which seems fairly common, yet I googled for similar questions but none seems up to date, so I hope someone can give a suggestion here. I cannot let ELMAH work in my mvc4 app once deployed onto an <strong>Azure</strong> web site, while it works fine when working locally on my development environment.</p>
  
  <p>Here are the details:</p>
  
  <p>1) I created an MVC4 web internet app, and added the <em>Elmah.MVC</em> NuGet package to it (the Elmah version as shown in the report page is 1.2.14706.955).</p>
  
  <p>2) I completed the modifications made to my web.config by (1) by adding:</p>
  
  <ul>
  <li><p>in <em>appSettings</em>:</p>
  
  <p>&lt;add key="elmah.mvc.disableHandler" value="false" />
  &lt;add key="elmah.mvc.disableHandleErrorFilter" value="false" />
  &lt;add key="elmah.mvc.requiresAuthentication" value="true" />
  &lt;add key="elmah.mvc.allowedRoles" value="administrator" />
  &lt;add key="elmah.mvc.route" value="elmah" /></p></li>
  <li><p>in <em>elmah</em>:</p>
  
  <p>&lt;security allowRemoteAccess="true" />
    &lt;errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="DefaultConnection" /></p></li>
  </ul>
  
  <p>My <em>DefaultConnection</em> string is a "standard" SqlServer string like:</p>
  
  <pre><code>&lt;add name="DefaultConnection" connectionString="Server=tcp:servername.database.windows.net,1433;Database=dbname;User ID=username;Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>Now, when working locally unhandled exceptions get logged into the database. When deployed on Azure, exceptions are raised, but nothing is logged into the (Azure SQL) database.</p>
  
  <p>I can successfully follow the route mywebsite/elmah both locally and remotely: only, when I try the remote route the elmah generated view shows no records, as nothing is stored in the database.</p>
  
  <p>The same remote database is used for user accounts and all other purposes, so I can be sure the web app can talk to the database. Simply, no exception ever gets logged once deployed on Azure.</p>
  
  <p>I created ELMAH tables and stored procs with the following SQL:</p>
  
  <pre><code>CREATE TABLE [dbo].[ELMAH_Error]
  (
      [ErrorId]     UNIQUEIDENTIFIER NOT NULL,
      [Application] NVARCHAR(60)  COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [Host]        NVARCHAR(50)  COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [Type]        NVARCHAR(100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [Source]      NVARCHAR(60)  COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [Message]     NVARCHAR(500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [User]        NVARCHAR(50)  COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
      [StatusCode]  INT NOT NULL,
      [TimeUtc]     DATETIME NOT NULL,
      [Sequence]    INT IDENTITY (1, 1) NOT NULL,
      [AllXml]      NTEXT COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL 
  ) 
  GO
  
  ALTER TABLE [dbo].[ELMAH_Error] WITH NOCHECK ADD 
      CONSTRAINT [PK_ELMAH_Error] PRIMARY KEY NONCLUSTERED ([ErrorId]) 
  GO
  
  ALTER TABLE [dbo].[ELMAH_Error] ADD 
      CONSTRAINT [DF_ELMAH_Error_ErrorId] DEFAULT (NEWID()) FOR [ErrorId]
  GO
  
  CREATE NONCLUSTERED INDEX [IX_ELMAH_Error_App_Time_Seq] ON [dbo].[ELMAH_Error] 
  (
      [Application]   ASC,
      [TimeUtc]       DESC,
      [Sequence]      DESC
  ) 
  GO
  
  /* ------------------------------------------------------------------------ 
          STORED PROCEDURES                                                      
     ------------------------------------------------------------------------ */
  
  SET QUOTED_IDENTIFIER ON 
  GO
  SET ANSI_NULLS ON 
  GO
  
  CREATE PROCEDURE [dbo].[ELMAH_GetErrorXml]
  (
      @Application NVARCHAR(60),
      @ErrorId UNIQUEIDENTIFIER
  )
  AS
  
      SET NOCOUNT ON
  
      SELECT 
          [AllXml]
      FROM 
          [ELMAH_Error]
      WHERE
          [ErrorId] = @ErrorId
      AND
          [Application] = @Application
  
  GO
  SET QUOTED_IDENTIFIER OFF 
  GO
  SET ANSI_NULLS ON 
  GO
  
  SET QUOTED_IDENTIFIER ON 
  GO
  SET ANSI_NULLS ON 
  GO
  
  CREATE PROCEDURE [dbo].[ELMAH_GetErrorsXml]
  (
      @Application NVARCHAR(60),
      @PageIndex INT = 0,
      @PageSize INT = 15,
      @TotalCount INT OUTPUT
  )
  AS 
  
      SET NOCOUNT ON
  
      DECLARE @FirstTimeUTC DATETIME
      DECLARE @FirstSequence INT
      DECLARE @StartRow INT
      DECLARE @StartRowIndex INT
  
      SELECT 
          @TotalCount = COUNT(1) 
      FROM 
          [ELMAH_Error]
      WHERE 
          [Application] = @Application
  
      -- Get the ID of the first error for the requested page
  
      SET @StartRowIndex = @PageIndex * @PageSize + 1
  
      IF @StartRowIndex &lt;= @TotalCount
      BEGIN
  
          SET ROWCOUNT @StartRowIndex
  
          SELECT  
              @FirstTimeUTC = [TimeUtc],
              @FirstSequence = [Sequence]
          FROM 
              [ELMAH_Error]
          WHERE   
              [Application] = @Application
          ORDER BY 
              [TimeUtc] DESC, 
              [Sequence] DESC
  
      END
      ELSE
      BEGIN
  
          SET @PageSize = 0
  
      END
  
      -- Now set the row count to the requested page size and get
      -- all records below it for the pertaining application.
  
      SET ROWCOUNT @PageSize
  
      SELECT 
          errorId     = [ErrorId], 
          application = [Application],
          host        = [Host], 
          type        = [Type],
          source      = [Source],
          message     = [Message],
          [user]      = [User],
          statusCode  = [StatusCode], 
          time        = CONVERT(VARCHAR(50), [TimeUtc], 126) + 'Z'
      FROM 
          [ELMAH_Error] error
      WHERE
          [Application] = @Application
      AND
          [TimeUtc] &lt;= @FirstTimeUTC
      AND 
          [Sequence] &lt;= @FirstSequence
      ORDER BY
          [TimeUtc] DESC, 
          [Sequence] DESC
      FOR
          XML AUTO
  
  GO
  SET QUOTED_IDENTIFIER OFF 
  GO
  SET ANSI_NULLS ON 
  GO
  
  SET QUOTED_IDENTIFIER ON 
  GO
  SET ANSI_NULLS ON 
  GO
  
  CREATE PROCEDURE [dbo].[ELMAH_LogError]
  (
      @ErrorId UNIQUEIDENTIFIER,
      @Application NVARCHAR(60),
      @Host NVARCHAR(30),
      @Type NVARCHAR(100),
      @Source NVARCHAR(60),
      @Message NVARCHAR(500),
      @User NVARCHAR(50),
      @AllXml NTEXT,
      @StatusCode INT,
      @TimeUtc DATETIME
  )
  AS
  
      SET NOCOUNT ON
  
      INSERT
      INTO
          [ELMAH_Error]
          (
              [ErrorId],
              [Application],
              [Host],
              [Type],
              [Source],
              [Message],
              [User],
              [AllXml],
              [StatusCode],
              [TimeUtc]
          )
      VALUES
          (
              @ErrorId,
              @Application,
              @Host,
              @Type,
              @Source,
              @Message,
              @User,
              @AllXml,
              @StatusCode,
              @TimeUtc
          )
  
  GO
  SET QUOTED_IDENTIFIER OFF 
  GO
  SET ANSI_NULLS ON 
  GO
  </code></pre>