sql-server - 等待操作超时

标签 sql-server asp.net-mvc

我对 MVC 代码优先应用程序开发比较陌生,我试图在 VPS 中托管 MVC 代码优先应用程序。当发布应用程序后尝试浏览网站时,我收到等待操作超时错误。我尝试做一些研究,发现在 SQL 上启用 TCP/IP 配置管理器帮助了一些,但我没有运气。下面添加的是堆栈跟踪,有人知道问题是什么吗?

[Win32Exception (0x80004005): The wait operation timed out]

[SqlException (0x80131904): Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.  This could be because the pre-login handshake failed or the server was unable to respond back in time.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=4223; handshake=2965; ]
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +356
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +117
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +267
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +318
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +211
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +393
   System.Data.SqlClient.SqlConnection.Open() +122
   System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +104
   System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +509
   System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection) +335
   System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +15
   System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +238
   System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements, DbTransaction existingTransaction) +271
   System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto) +1232
   System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration) +524
   System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId) +193
   System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration) +609
   System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +613
   System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) +116
   System.Data.Entity.MigrateDatabaseToLatestVersion`2.InitializeDatabase(TContext context) +156
   System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +72
   System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +483
   System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +177
   System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +274
   System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes() +63
   System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext() +31
   OfficeTrack.DAL.Context.MasterContext..ctor() +47
   OfficeTrack.Web.MvcApplication.Application_Start() +206

[HttpException (0x80004005): Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.  This could be because the pre-login handshake failed or the server was unable to respond back in time.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=4223; handshake=2965; ]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +544
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +186
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +402
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +343

[HttpException (0x80004005): Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.  This could be because the pre-login handshake failed or the server was unable to respond back in time.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=4223; handshake=2965; ]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +712

最佳答案

我也遇到了同样的问题。某些 SQL 升级命令运行时间很长并导致错误,因为默认超时设置为 30 秒。我找到了以下关于 SO 的文章来解决这个问题: EF Code First - Timeout expired. The timeout period elapsed prior to completion

对我来说,它可以在 Configuration.cs 文件中将 CommandTimeout 设置为 180 秒。

祝你好运

关于sql-server - 等待操作超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36909490/

相关文章:

c# - 如何使用 ASP.NET 在负载平衡服务器上存储和检索上传的图像?

sql-server - SQL服务器事务

sql-server - EXECUTE 后的事务计数表明 BEGIN 和 COMMIT 的数量不匹配

mysql - MySQL中可以使用命令更改数据库的默认路径吗?

c# - Umbraco 7 Razor - 找到父级

javascript - MVC Jquery/ Controller 后重定向

mysql - SQL组查询从两个表中获取数据

sql - 存储过程中的 IF/ELSE 性能

javascript - MVC : Javascript confirm for delete action not working

jquery - JsonResult 和 ajax.BeginForm 之间的区别