2

我在 rackspace 云服务器上托管了我的网站。

有时我在从数据库中获取记录时遇到以下异常。奇怪的是,在重新启动后的几天内一切正常,而且我只在少数地方而不是所有地方都得到了这个异常。

Exception: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

Stack Trace:


[SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +59
   System.Data.SqlClient.SqlDataReader.get_MetaData() +118
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6387937
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6389506
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +538
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +28
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +256
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +19
   System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +553

[EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.]
   DataAccessLayer.dbCustomer.CompanyCustomerByLocationId(String sortExpression, Boolean asc, String nameSearchString, Int32 startRowIndex, Int32 maximumRows, Int32& TotalRecord, Int64 companyId) in D:\Dotnet Projects\FutureZoom\FutureZoom\DataAccessLayer\dbCustomer.cs:508
   BusinessLogic.Customer.CompanyCustomerByLocationId(String sortExpression, Boolean asc, String nameSearchString, Int32 startRowIndex, Int32 maximumRows, Int64 CompanyId) in D:\Dotnet Projects\FutureZoom\FutureZoom\BusinessLogic\Customer.cs:431
   FutureZoom.Areas.Admin.Controllers.CompanyController.CustomerPaging(Int32 StartIndex, Int32 PageSize, String SortExp, Boolean Asc, String SearchExp, String Where) in D:\Dotnet Projects\FutureZoom\FutureZoom\FutureZoom\Areas\Admin\Controllers\CompanyController.cs:552
   lambda_method(Closure , ControllerBase , Object[] ) +362
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +248
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +125
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +312
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +691
   System.Web.Mvc.Controller.ExecuteCore() +162
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +305
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

下面提到了我的 Linq 查询

query = context.Customers.Include("Company").Include("Company.EmailCampaignerStatus")
                                           .OrderBy(m => m.EmailCampaignerStatus.FirstOrDefault().CreatedOn)                                           
                                           .Where(m => m.FirstName.StartsWith(name) || m.LastName.StartsWith(name) || m.Email.StartsWith(name) || (m.FirstName + " " + m.LastName).StartsWith(name))
                                           .Where(m => m.CompanyId == companyId)
                                           .Where(m => m.CompanyLocationId == locationId)
                                           .Skip(startRowIndex == 0 ? startRowIndex : startRowIndex - 1)
                                           .Take(maximumRows)
                                           .ToList();

此查询的执行时间在我的本地计算机上甚至不是 1 秒,并且在重新启动后在服务器端也是相同的,但是执行时间每天都在增加,并且在几天后无法执行(有时会失败,有时会给出结果)。

我观察到它花费了 31.05 秒并且失败了,它花费了 51.09 秒并且失败了。有时需要超过 2 分钟并给出结果。

我与 rackspace 的人交谈过,但他们无法追踪相同的实际原因。

编辑 1:我在 SQL Profiler 中看到以下针对我的分页查询的查询

SELECT 
[Project3].[Id1] AS [Id], 
[Project3].[C1] AS [C1], 
[Project3].[Id] AS [Id1], 
[Project3].[CompanyId] AS [CompanyId], 
[Project3].[CompanyLocationId] AS [CompanyLocationId], 
[Project3].[FirstName] AS [FirstName], 
[Project3].[LastName] AS [LastName], 
[Project3].[Email] AS [Email], 
[Project3].[Address1] AS [Address1], 
[Project3].[Address2] AS [Address2], 
[Project3].[City] AS [City], 
[Project3].[State] AS [State], 
[Project3].[Country] AS [Country], 
[Project3].[Zip] AS [Zip], 
[Project3].[Phone] AS [Phone], 
[Project3].[SaleDate] AS [SaleDate], 
[Project3].[Notes] AS [Notes], 
[Project3].[Cost] AS [Cost], 
[Project3].[CreatedOn] AS [CreatedOn], 
[Project3].[ModifiedOn] AS [ModifiedOn], 
[Project3].[PrimaryReviewSiteId] AS [PrimaryReviewSiteId], 
[Project3].[Id2] AS [Id2], 
[Project3].[SubscriptionTypeId] AS [SubscriptionTypeId], 
[Project3].[PlanFeeAmount] AS [PlanFeeAmount], 
[Project3].[LoginId] AS [LoginId], 
[Project3].[IndustryTypeId] AS [IndustryTypeId], 
[Project3].[CompanyName] AS [CompanyName], 
[Project3].[NumberOfLocations] AS [NumberOfLocations], 
[Project3].[LogoImageName] AS [LogoImageName], 
[Project3].[WebsiteUrl] AS [WebsiteUrl], 
[Project3].[blsActive] AS [blsActive], 
[Project3].[Pending] AS [Pending], 
[Project3].[ExpiryDate] AS [ExpiryDate], 
[Project3].[C2] AS [C2], 
[Project3].[Id3] AS [Id3], 
[Project3].[UploadTicketId] AS [UploadTicketId], 
[Project3].[UploadStatus] AS [UploadStatus], 
[Project3].[CompanyId1] AS [CompanyId1], 
[Project3].[CompanyLocationId1] AS [CompanyLocationId1], 
[Project3].[CustomerId] AS [CustomerId], 
[Project3].[CreatedOn2] AS [CreatedOn1]
FROM ( SELECT 
    [Limit2].[Id] AS [Id], 
    [Limit2].[CompanyId] AS [CompanyId], 
    [Limit2].[CompanyLocationId] AS [CompanyLocationId], 
    [Limit2].[FirstName] AS [FirstName], 
    [Limit2].[LastName] AS [LastName], 
    [Limit2].[Email] AS [Email], 
    [Limit2].[Address1] AS [Address1], 
    [Limit2].[Address2] AS [Address2], 
    [Limit2].[City] AS [City], 
    [Limit2].[State] AS [State], 
    [Limit2].[Country] AS [Country], 
    [Limit2].[Zip] AS [Zip], 
    [Limit2].[Phone] AS [Phone], 
    [Limit2].[SaleDate] AS [SaleDate], 
    [Limit2].[Notes] AS [Notes], 
    [Limit2].[Cost] AS [Cost], 
    [Limit2].[CreatedOn] AS [CreatedOn], 
    [Limit2].[ModifiedOn] AS [ModifiedOn], 
    [Limit2].[PrimaryReviewSiteId] AS [PrimaryReviewSiteId], 
    [Limit2].[Id1] AS [Id1], 
    [Limit2].[CreatedOn1] AS [CreatedOn1], 
    [Limit2].[Id2] AS [Id2], 
    [Limit2].[SubscriptionTypeId] AS [SubscriptionTypeId], 
    [Limit2].[PlanFeeAmount] AS [PlanFeeAmount], 
    [Limit2].[LoginId] AS [LoginId], 
    [Limit2].[IndustryTypeId] AS [IndustryTypeId], 
    [Limit2].[CompanyName] AS [CompanyName], 
    [Limit2].[NumberOfLocations] AS [NumberOfLocations], 
    [Limit2].[WebsiteUrl] AS [WebsiteUrl], 
    [Limit2].[blsActive] AS [blsActive], 
    [Limit2].[Pending] AS [Pending], 
    [Limit2].[ExpiryDate] AS [ExpiryDate], 
    [Limit2].[LogoImageName] AS [LogoImageName], 
    [Limit2].[C1] AS [C1], 
    [Extent4].[Id] AS [Id3], 
    [Extent4].[UploadTicketId] AS [UploadTicketId], 
    [Extent4].[UploadStatus] AS [UploadStatus], 
    [Extent4].[CompanyId] AS [CompanyId1], 
    [Extent4].[CompanyLocationId] AS [CompanyLocationId1], 
    [Extent4].[CustomerId] AS [CustomerId], 
    [Extent4].[CreatedOn] AS [CreatedOn2], 
    CASE WHEN ([Extent4].[Id] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C2]
    FROM   (SELECT TOP (20) [Project2].[Id] AS [Id], [Project2].[CompanyId] AS [CompanyId], [Project2].[CompanyLocationId] AS [CompanyLocationId], [Project2].[FirstName] AS [FirstName], [Project2].[LastName] AS [LastName], [Project2].[Email] AS [Email], [Project2].[Address1] AS [Address1], [Project2].[Address2] AS [Address2], [Project2].[City] AS [City], [Project2].[State] AS [State], [Project2].[Country] AS [Country], [Project2].[Zip] AS [Zip], [Project2].[Phone] AS [Phone], [Project2].[SaleDate] AS [SaleDate], [Project2].[Notes] AS [Notes], [Project2].[Cost] AS [Cost], [Project2].[CreatedOn] AS [CreatedOn], [Project2].[ModifiedOn] AS [ModifiedOn], [Project2].[PrimaryReviewSiteId] AS [PrimaryReviewSiteId], [Project2].[Id1] AS [Id1], [Project2].[CreatedOn1] AS [CreatedOn1], [Project2].[Id2] AS [Id2], [Project2].[SubscriptionTypeId] AS [SubscriptionTypeId], [Project2].[PlanFeeAmount] AS [PlanFeeAmount], [Project2].[LoginId] AS [LoginId], [Project2].[IndustryTypeId] AS [IndustryTypeId], [Project2].[CompanyName] AS [CompanyName], [Project2].[NumberOfLocations] AS [NumberOfLocations], [Project2].[WebsiteUrl] AS [WebsiteUrl], [Project2].[blsActive] AS [blsActive], [Project2].[Pending] AS [Pending], [Project2].[ExpiryDate] AS [ExpiryDate], [Project2].[LogoImageName] AS [LogoImageName], [Project2].[C1] AS [C1]
        FROM ( SELECT [Project2].[Id] AS [Id], [Project2].[CompanyId] AS [CompanyId], [Project2].[CompanyLocationId] AS [CompanyLocationId], [Project2].[FirstName] AS [FirstName], [Project2].[LastName] AS [LastName], [Project2].[Email] AS [Email], [Project2].[Address1] AS [Address1], [Project2].[Address2] AS [Address2], [Project2].[City] AS [City], [Project2].[State] AS [State], [Project2].[Country] AS [Country], [Project2].[Zip] AS [Zip], [Project2].[Phone] AS [Phone], [Project2].[SaleDate] AS [SaleDate], [Project2].[Notes] AS [Notes], [Project2].[Cost] AS [Cost], [Project2].[CreatedOn] AS [CreatedOn], [Project2].[ModifiedOn] AS [ModifiedOn], [Project2].[PrimaryReviewSiteId] AS [PrimaryReviewSiteId], [Project2].[Id1] AS [Id1], [Project2].[CreatedOn1] AS [CreatedOn1], [Project2].[Id2] AS [Id2], [Project2].[SubscriptionTypeId] AS [SubscriptionTypeId], [Project2].[PlanFeeAmount] AS [PlanFeeAmount], [Project2].[LoginId] AS [LoginId], [Project2].[IndustryTypeId] AS [IndustryTypeId], [Project2].[CompanyName] AS [CompanyName], [Project2].[NumberOfLocations] AS [NumberOfLocations], [Project2].[WebsiteUrl] AS [WebsiteUrl], [Project2].[blsActive] AS [blsActive], [Project2].[Pending] AS [Pending], [Project2].[ExpiryDate] AS [ExpiryDate], [Project2].[LogoImageName] AS [LogoImageName], [Project2].[C1] AS [C1], row_number() OVER (ORDER BY [Project2].[CreatedOn1] ASC) AS [row_number]
            FROM ( SELECT 
                [Filter1].[Id] AS [Id], 
                [Filter1].[CompanyId] AS [CompanyId], 
                [Filter1].[CompanyLocationId] AS [CompanyLocationId], 
                [Filter1].[FirstName] AS [FirstName], 
                [Filter1].[LastName] AS [LastName], 
                [Filter1].[Email] AS [Email], 
                [Filter1].[Address1] AS [Address1], 
                [Filter1].[Address2] AS [Address2], 
                [Filter1].[City] AS [City], 
                [Filter1].[State] AS [State], 
                [Filter1].[Country] AS [Country], 
                [Filter1].[Zip] AS [Zip], 
                [Filter1].[Phone] AS [Phone], 
                [Filter1].[SaleDate] AS [SaleDate], 
                [Filter1].[Notes] AS [Notes], 
                [Filter1].[Cost] AS [Cost], 
                [Filter1].[CreatedOn] AS [CreatedOn], 
                [Filter1].[ModifiedOn] AS [ModifiedOn], 
                [Filter1].[PrimaryReviewSiteId] AS [PrimaryReviewSiteId], 
                [Limit1].[Id] AS [Id1], 
                [Limit1].[CreatedOn] AS [CreatedOn1], 
                [Extent3].[Id] AS [Id2], 
                [Extent3].[SubscriptionTypeId] AS [SubscriptionTypeId], 
                [Extent3].[PlanFeeAmount] AS [PlanFeeAmount], 
                [Extent3].[LoginId] AS [LoginId], 
                [Extent3].[IndustryTypeId] AS [IndustryTypeId], 
                [Extent3].[CompanyName] AS [CompanyName], 
                [Extent3].[NumberOfLocations] AS [NumberOfLocations], 
                [Extent3].[WebsiteUrl] AS [WebsiteUrl], 
                [Extent3].[blsActive] AS [blsActive], 
                [Extent3].[Pending] AS [Pending], 
                [Extent3].[ExpiryDate] AS [ExpiryDate], 
                [Extent3].[LogoImageName] AS [LogoImageName], 
                1 AS [C1]
                FROM    (SELECT [Extent1].[Id] AS [Id], [Extent1].[CompanyId] AS [CompanyId], [Extent1].[CompanyLocationId] AS [CompanyLocationId], [Extent1].[FirstName] AS [FirstName], [Extent1].[LastName] AS [LastName], [Extent1].[Email] AS [Email], [Extent1].[Address1] AS [Address1], [Extent1].[Address2] AS [Address2], [Extent1].[City] AS [City], [Extent1].[State] AS [State], [Extent1].[Country] AS [Country], [Extent1].[Zip] AS [Zip], [Extent1].[Phone] AS [Phone], [Extent1].[SaleDate] AS [SaleDate], [Extent1].[Notes] AS [Notes], [Extent1].[Cost] AS [Cost], [Extent1].[CreatedOn] AS [CreatedOn], [Extent1].[ModifiedOn] AS [ModifiedOn], [Extent1].[PrimaryReviewSiteId] AS [PrimaryReviewSiteId]
                    FROM [dbo].[Customer] AS [Extent1]
                    WHERE (([Extent1].[FirstName] LIKE @p__linq__0 ESCAPE N'~') OR ([Extent1].[LastName] LIKE @p__linq__1 ESCAPE N'~') OR ([Extent1].[Email] LIKE @p__linq__2 ESCAPE N'~') OR ([Extent1].[FirstName] + N' ' + [Extent1].[LastName] LIKE @p__linq__3 ESCAPE N'~')) AND ([Extent1].[CompanyId] = @p__linq__4) AND ([Extent1].[CompanyLocationId] = @p__linq__5) ) AS [Filter1]
                OUTER APPLY  (SELECT TOP (1) 
                    [Extent2].[Id] AS [Id], 
                    [Extent2].[CreatedOn] AS [CreatedOn]
                    FROM [dbo].[EmailCampaignerStatus] AS [Extent2]
                    WHERE [Filter1].[Id] = [Extent2].[CustomerId] ) AS [Limit1]
                LEFT OUTER JOIN [dbo].[Company] AS [Extent3] ON [Filter1].[CompanyId] = [Extent3].[Id]
            )  AS [Project2]
        )  AS [Project2]
        WHERE [Project2].[row_number] > 0
        ORDER BY [Project2].[CreatedOn1] ASC ) AS [Limit2]
    LEFT OUTER JOIN [dbo].[EmailCampaignerStatus] AS [Extent4] ON [Limit2].[CompanyId] = [Extent4].[CompanyId]
)  AS [Project3]
ORDER BY [Project3].[CreatedOn1] ASC, [Project3].[Id1] ASC, [Project3].[Id] ASC, [Project3].[Id2] ASC, [Project3].[C2] ASC

SELECT 
[GroupBy1].[A1] AS [C1]
FROM ( SELECT 
    COUNT(1) AS [A1]
    FROM [dbo].[Customer] AS [Extent1]
    WHERE (([Extent1].[FirstName] LIKE @p__linq__0 ESCAPE N'~') OR ([Extent1].[LastName] LIKE @p__linq__1 ESCAPE N'~') OR ([Extent1].[Email] LIKE @p__linq__2 ESCAPE N'~') OR ([Extent1].[FirstName] + N' ' + [Extent1].[LastName] LIKE @p__linq__3 ESCAPE N'~')) AND ([Extent1].[CompanyId] = @p__linq__4) AND ([Extent1].[CompanyLocationId] = @p__linq__5)
)  AS [GroupBy1]


SELECT 
CASE WHEN ( EXISTS (SELECT 
    1 AS [C1]
    FROM [dbo].[CompanyReviewSites] AS [Extent1]
    WHERE [Extent1].[CompanyLocationId] = @p__linq__0
)) THEN cast(1 as bit) WHEN ( NOT EXISTS (SELECT 
    1 AS [C1]
    FROM [dbo].[CompanyReviewSites] AS [Extent2]
    WHERE [Extent2].[CompanyLocationId] = @p__linq__0
)) THEN cast(0 as bit) END AS [C1]
FROM  ( SELECT 1 AS X ) AS [SingleRowTable1]

SELECT 
1 AS [C1], 
[Extent1].[Id] AS [Id], 
[Extent1].[RiviewSiteId] AS [RiviewSiteId], 
[Extent1].[URL] AS [URL], 
[Extent1].[CompanyId] AS [CompanyId], 
[Extent1].[CompanyLocationId] AS [CompanyLocationId], 
[Extent2].[Id] AS [Id1], 
[Extent2].[ReviewSiteName] AS [ReviewSiteName], 
[Extent2].[ImageName] AS [ImageName]
FROM  [dbo].[CompanyReviewSites] AS [Extent1]
INNER JOIN [dbo].[ReviewSites] AS [Extent2] ON [Extent1].[RiviewSiteId] = [Extent2].[Id]
WHERE [Extent1].[CompanyLocationId] = @p__linq__0
4

5 回答 5

2

这可能有很多原因:

  • 来自失败事务的锁
  • 索引问题
  • 如果它是共享服务器,则来自另一个应用程序的资源竞争
  • 备份不清除事务日志
  • 相关磁盘空间问题

您是否能够获取 SQL 服务器日志、查看活动监视器或运行 SQL 分析器。根据我的经验,这样的问题很难追查,所以只能祝你好运

于 2012-10-18T06:06:22.130 回答
2

当我遇到类似的问题时;我们的服务器实际上是在索引每个查询之后。此外,在整个公司大量使用之后,它随机出现了类似的问题。我通过以下方式解决了它:

处理临时对象/包装在 using 语句中。这使我可以保留内存中存储的任何对象、查询或任何数据以进行转储。

另一个问题;我们的一位开发人员在整个应用程序中不断打开/关闭连接。我试图创建用法;打开它一次,然后一次完成所有需要的任务。它可能会强制进行一些重新设计;但它使它更健壮。甚至不在每个单独的班级中打开/关闭;但是,当您准备好提交它,然后在课程开放时添加那些所需的课程也可能会有所帮助。

下一个难题是验证所有缓存的项目都已清除。因此,您不必经常存储它。

另一个项目是更改我们的 Windows 虚拟机索引。

处置/使用的示例:http: //msdn.microsoft.com/en-us/library/fs2xkftw.aspx

public void SqlTransactionHere()
{
       SqlTransaction tran = myConnection.BeginTransaction();
       tran.Dispose();
}

帮助维护连接的示例;然后进行调用,我们使用了类似于以下的模式:

http://msdn.microsoft.com/en-us/magazine/cc947917.aspx

我们对服务器也做了一些调整;当我们的服务器开始分页并在内存中存储太多数据时,这也陷入了困境。

您可以监控您的服务器;通过执行以下步骤:

  1. Windows 键 + R(运行)
  2. 电源外壳
  3. 然后输入:

    strComputer = "-" Set objWmiService = GetObject("winmgmts:\" & strComputer & "\root\cimv2") Set colPageFiles = objWMIService.ExecQuery("Select * from Win32_PageFileSetting")

    对于 colPageFiles 中的每个 objPageFile objPageFile.InitialSize = 384 objPageFile.MaximumSize = 1152 objPageFile.Put_ Next

以上适用于 256 mb 内存;“微软最佳”。我们实际上把我们的初始大小缩小到 50;最大大小为 384。我们的服务器在开始时确实标记了一个错误,指出我们将虚拟内存设置得太低。然而; 我们的服务器性能和我们的应用程序一样提高了。您实际上可以监控它的内存使用情况/虚拟内存使用情况来帮助计算。

如果您也想编写应用程序,请为您监视和记录;或者想使用微软的内置控件:http: //msdn.microsoft.com/en-us/library/system.diagnostics.process.virtualmemorysize64.aspx

  1. 开始
  2. 管理工具(如果没有,控制面板 --> 管理工具)
  3. 系统监视器
  4. PageFile 和其他要监视的组件。%Usage 然后添加
  5. 应该开始为您跟踪。

您也可以在注册表中更改它:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management

您还可以清除缓存。这可以通过利用来完成:

  • DBCC 删除缓冲区
  • 检查点

它们可以帮助清除一些与缓存相关的问题;重新启动 SQL Server 或 Windows 完成同样的事情。这就是为什么它可以解决您的问题。但再次发生;如果它太长。

这是一篇关于 SQL 性能脚本的精彩文章:

http://sqlcat.com/sqlcat/b/toolbox/archive/2008/02/21/scripts-and-tools-for-performance-tuning-and-troubleshooting-sql-server-2005.aspx

这篇文章非常适合帮助解决或查找性能问题:http: //support.microsoft.com/kb/298475

或者,如果您不想这样做,因为它正在工作,但在使用几天和大量使用后确实会引发异常。您可以简单地创建一个 powershell 脚本;和:

脚本:“按时间安排设置”重新启动计算机 -ComputerName localhost

然后只需转到您的注册表:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
  1. 双击默认用户名
  2. 输入服务器登录
  3. 双击默认密码
  4. 输入你的密码。
  5. 将 AutoAdminLogin 值更改为 1

您也可以编辑或添加字符串值。如果它不存在。

希望这些对您有所帮助;这些是我们为了解决我们的问题而必须做的一些事情。你可能只需要做一个,或者什么都不做。但我确实希望这有助于或为社区提供一些想法,以帮助更好地解决您的问题。

但对我来说,这听起来像是您的服务器内存陷入困境,数据过多并且由于机器陷入困境而无法解析或运行命令。我假设您使用的是 Windows Server,否则那些 Powershell 脚本命令就没用了。

于 2012-11-06T21:57:35.523 回答
1

如果其他人来这里寻找这个问题的答案,我有同样的问题,我的问题是 SQL Server 正在缓存结果。

我必须添加OPTION (RECOMPILE)到我的 SQL 查询的末尾。

我问了同样的问题,可以在我的问题的答案中找到解释:EntityCommandExecutionException Timeout Expired Only Some Some

于 2017-06-16T17:42:40.843 回答
0

我认为这是索引和刷新所有索引临时数据的问题。这称为统计数据,当 SQL 服务器收集所有可能的缓存变化时,它会将它们用作索引服务的现金。因此更新 SQL 数据库中的统计数据可能会有所帮助

DECLARE @SQL VARCHAR(1000)  
DECLARE @DB sysname  

DECLARE curDB CURSOR FORWARD_ONLY STATIC FOR  
   SELECT [name]  
   FROM master..sysdatabases 
   WHERE [name] NOT IN ('model', 'tempdb') 
   ORDER BY [name] 

OPEN curDB  
FETCH NEXT FROM curDB INTO @DB  
WHILE @@FETCH_STATUS = 0  
   BEGIN  
       SELECT @SQL = 'USE [' + @DB +']' + CHAR(13) + 'EXEC sp_updatestats' + CHAR(13)  
       PRINT @SQL  
       FETCH NEXT FROM curDB INTO @DB  
   END  

CLOSE curDB  
DEALLOCATE curDB

然后执行该查询...

于 2012-11-01T14:01:54.597 回答
0

有几件事浮现在脑海。您是否进行过负载测试?它可能在您的机器和服务器上单独工作,但几天后有几千次点击,那么它可能会有所不同。这似乎是您提到的行为。

也许第一个查询只有 200 行,但第三天的相同查询必须搜索 200 万行,这会使事情变慢一点。

正如其他人所建议的那样。看看改进您的数据库表上的索引(如果这是一个选项)。

是否可以重新编写您的 Linq 查询。也许它的编写方式是防止 SQL 将查询执行计划缓存在 RAM 中。

服务器本身是否正在备份?当托管公司通过拍摄我们的数据库所在的虚拟机的快照来影响工作时,我有过实例,而不是基于云的服务器。

于 2012-11-02T16:45:48.087 回答