Azure SQL Database is fully occupied without requests

1

I am using an Azure Web App (own ASP.NET Project) combined with an Azure SQL database. My web application is requesting the database on each request to check the userlevel for example.

The workload on the Azure charts are totally normal but sometimes there are some strange workloads after special events. For example I worked on the ASP.NET Project yesterday at 9PM on my local machine without publishing or opening the Server Explorers. I also did not update the firewall IP in Azure for accessing the database from my local machine.

After a hour of work I noticed that the website was sending back a 502 Error after loading for 1.5 minutes. I took a look on the charts and noticed that the database was occupied by requests since I started programming on the local machine.

Trying to republish, restart the server and changing the database pricing tier did not help.

The Azure Web App Chart:

Workload Web App

The Azure SQL Database Chart:

Workload Database

I have no idea why this happens because it is not the first time and the downtime is not that short.

--- EDIT: ---

As @DanRediske-MSFT mentioned below I tracked the SQL queries in the Management Studio and saw that there is one statement which is using a lot of resources (is executing extremely long):

Statement Resources Chart

The SQL big resource statement is really long because it is generated by the Entity Framework:

SELECT 
   [Project1].[AccessFailedCount] AS [AccessFailedCount], 
   [Project1].[Id] AS [Id], 
   [Project1].[UserDomain] AS [UserDomain], 
   [Project1].[Email] AS [Email], 
   [Project1].[EmailConfirmed] AS [EmailConfirmed], 
   [Project1].[PasswordHash] AS [PasswordHash], 
   [Project1].[SecurityStamp] AS [SecurityStamp], 
   [Project1].[UserName] AS [UserName], 
   [Project1].[AccountDetail_Id] AS [AccountDetail_Id], 
   [Project1].[AccountSetting_Id] AS [AccountSetting_Id], 
   [Project1].[BusinessDetail_Id] AS [BusinessDetail_Id], 
   [Project1].[LeadCollection_Id] AS [LeadCollection_Id], 
   [Project1].[PaymentDetail_Id] AS [PaymentDetail_Id], 
   [Project1].[UserDetail_Id] AS [UserDetail_Id], 
   [Project1].[C2] AS [C1], 
   [Project1].[Id1] AS [Id1], 
   [Project1].[OrderDate] AS [OrderDate], 
   [Project1].[OrderNumber] AS [OrderNumber], 
   [Project1].[HasBeenHandled] AS [HasBeenHandled], 
   [Project1].[OrderId] AS [OrderId], 
   [Project1].[PaypalSubscriptionID] AS [PaypalSubscriptionID], 
   [Project1].[IsActive] AS [IsActive], 
   [Project1].[Product_ProductID] AS [Product_ProductID], 
   [Project1].[User_Id] AS [User_Id], 
   [Project1].[C1] AS [C2], 
   [Project1].[PaymentID] AS [PaymentID], 
   [Project1].[PaymentDate] AS [PaymentDate], 
   [Project1].[Amount] AS [Amount], 
   [Project1].[HasBeenHandled1] AS [HasBeenHandled1], 
   [Project1].[TransactionID] AS [TransactionID], 
   [Project1].[Order_ID] AS [Order_ID]
   FROM ( SELECT 
       [Extent1].[Id] AS [Id], 
       [Extent1].[UserDomain] AS [UserDomain], 
       [Extent1].[Email] AS [Email], 
       [Extent1].[EmailConfirmed] AS [EmailConfirmed], 
       [Extent1].[PasswordHash] AS [PasswordHash], 
       [Extent1].[SecurityStamp] AS [SecurityStamp], 
       [Extent1].[AccessFailedCount] AS [AccessFailedCount], 
       [Extent1].[UserName] AS [UserName], 
       [Extent1].[AccountDetail_Id] AS [AccountDetail_Id], 
       [Extent1].[AccountSetting_Id] AS [AccountSetting_Id], 
       [Extent1].[BusinessDetail_Id] AS [BusinessDetail_Id], 
       [Extent1].[LeadCollection_Id] AS [LeadCollection_Id], 
       [Extent1].[PaymentDetail_Id] AS [PaymentDetail_Id], 
       [Extent1].[UserDetail_Id] AS [UserDetail_Id], 
       [Join2].[ID] AS [Id1], 
       [Join2].[OrderDate] AS [OrderDate], 
       [Join2].[OrderNumber] AS [OrderNumber], 
       [Join2].[HasBeenHandled1] AS [HasBeenHandled], 
       [Join2].[Product_ProductID] AS [Product_ProductID], 
       [Join2].[User_Id] AS [User_Id], 
       [Join2].[OrderId] AS [OrderId], 
       [Join2].[PaypalSubscriptionID] AS [PaypalSubscriptionID], 
       [Join2].[IsActive] AS [IsActive], 
       [Join2].[PaymentID] AS [PaymentID], 
       [Join2].[PaymentDate] AS [PaymentDate], 
       [Join2].[Amount] AS [Amount], 
       [Join2].[HasBeenHandled2] AS [HasBeenHandled1], 
       [Join2].[TransactionID] AS [TransactionID], 
       [Join2].[Order_ID] AS [Order_ID], 
       CASE WHEN ([Join2].[ID] IS NULL) THEN CAST(NULL AS int) WHEN ([Join2].[PaymentID] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1], 
       CASE WHEN ([Join2].[ID] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C2]
       FROM  [dbo].[AspNetUsers] AS [Extent1]
       LEFT OUTER JOIN  (SELECT [Extent2].[ID] AS [ID], [Extent2].[OrderDate] AS [OrderDate], [Extent2].[OrderNumber] AS [OrderNumber], [Extent2].[HasBeenHandled] AS [HasBeenHandled1], [Extent2].[Product_ProductID] AS [Product_ProductID], [Extent2].[User_Id] AS [User_Id], [Extent3].[OrderId] AS [OrderId], [Extent3].[PaypalSubscriptionID] AS [PaypalSubscriptionID], [Extent3].[IsActive] AS [IsActive], [Extent4].[PaymentID] AS [PaymentID], [Extent4].[PaymentDate] AS [PaymentDate], [Extent4].[Amount] AS [Amount], [Extent4].[HasBeenHandled] AS [HasBeenHandled2], [Extent4].[TransactionID] AS [TransactionID], [Extent4].[Order_ID] AS [Order_ID]
           FROM   [dbo]

It looks like the statement would not be complete but that's all I see in the .sqlplan file StatementText Attribute. So here it would be the complete file for that statement: http://alexpower.de/snippet.sqlplan

For me it now would be intresting to know which EF code is generating that statement. Is this possible to get that information?

--- EDIT: ---

Found some interesting Events in the Event Viewer on domainname.scm.azurewebsites.net/Support but don't know what to do with it:

Info:

.NET Runtime version 4.0.30319.0 - Loading profiler failed. Failed trying to receive from out of process a request to attach a profiler. HRESULT: 0x8007006d. Process ID (decimal): 4716. Message ID: [0x250d].

Warning:

Worker Process requested recycle due to 'Percent Slow Requests' limit.

Error:

Event code: 3005 Event message: An unhandled exception has occurred. Event time: 3/22/2017 9:47:27 PM Event time (UTC): 3/22/2017 8:47:27 PM Event ID: 919f06b7f5e647beb75be7c8400d107f Event sequence: 8 Event occurrence: 1 Event detail code: 0

Application information: Application domain: /LM/W3SVC/712043775/ROOT-1-131346876896158300 Trust level: Full Application Virtual Path: / Application Path: D:\Program Files (x86)\SiteExtensions\Kudu\61.60316.2745\ Machine name: RD00155D56FC01

Process information: Process ID: 5064 Process name: w3wp.exe Account name: IIS APPPOOL\onlineplaybook

Exception information: Exception type: HttpException Exception message: Server cannot append header after HTTP headers have been sent. at System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace) at System.Web.HttpHeaderCollection.Add(String name, String value) at Kudu.Services.Web.Tracing.TraceModule.OnBeginRequest(Object sender, EventArgs e) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Request information: Request URL: https://onlineplaybook.scm.azurewebsites.net:443/msdeploy.axd?site=onlineplaybook Request path: /msdeploy.axd User host address: 79.248.163.180 User: Is authenticated: False Authentication Type: Thread account name: IIS APPPOOL\onlineplaybook

Thread information: Thread ID: 20 Thread account name: IIS APPPOOL\onlineplaybook Is impersonating: False Stack trace: at System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace) at System.Web.HttpHeaderCollection.Add(String name, String value) at Kudu.Services.Web.Tracing.TraceModule.OnBeginRequest(Object sender, EventArgs e) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Custom event details:

asp.net
entity-framework
azure
azure-sql-database
asked on Stack Overflow Mar 20, 2017 by Alex • edited Mar 22, 2017 by Alex

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0