使用 WEB API 和实体框架项目的 IIS 本地计算机上"The underlying provider failed to Open"异常



我有一个与本地 IIS Express 完美配合的 Web API 2 项目,但是当我在本地机器 IIS 上部署时,出现以下错误:

{
  "Message": "An error has occurred.",
  "ExceptionMessage": "The underlying provider failed on Open.",
  "ExceptionType": "System.Data.Entity.Core.EntityException",
  "StackTrace": "   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()rn   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection()rn   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)rn   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass49.<ExecuteFunction>b__47()rn   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)rn   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction(String functionName, ObjectParameter[] parameters)rn   at ServiceDBUtility.FamLinkEntities.MBSP_INSERT_ERROR_LOG(String p_ID_USER, String p_ERROR_MSG, String p_ERROR_TRACE, String p_ERROR_TYPE, String p_REQUEST_URL, Nullable`1 p_ERROR_DATE)rn   at ServiceDBUtility.Repository.LogRepository.WriteLog(String p_ID_USER, String p_ERROR_MSG, String p_ERROR_TRACE, String p_ERROR_TYPE, String p_REQUEST_URL, Nullable`1 p_ERROR_DATE)rn   at ServiceDBUtility.CommonFunctions.WriteLog(String USER_ID, Exception Ex, String reqURL)rn   at ServiceDBUtility.CommonFunctions.ThrowException(Exception e, HttpRequestMessage request, String customErrorMessage)rn   at LoginService.Controllers.LoginController.Login()rn   at lambda_method(Closure , Object , Object[] )rn   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)rn   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)rn--- End of stack trace from previous location where exception was thrown ---rn   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)rn   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)rn   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)rn   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)rn   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()rn--- End of stack trace from previous location where exception was thrown ---rn   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)rn   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()",
  "InnerException": {
    "Message": "An error has occurred.",
    "ExceptionMessage": "Login failed for user ''.",
    "ExceptionType": "System.Data.SqlClient.SqlException",
    "StackTrace": "   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)rn   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)rn   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)rn   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)rn   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)rn   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)rn   at System.Data.SqlClient.SqlConnection.Open()rn   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()rn   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)rn   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()"
  }
}

有人可以提供可能导致此错误的原因的见解吗?

这就是

我解决这个问题的方式,

  1. 按 WIN + R
  2. 键入 inetmgr 并按回车键
  3. 选择应用程序池
  4. 从右侧选择高级设置
  5. 转到"标识",然后选择"自定义帐户"
  6. 提供活动目录的用户名和密码。

@mahesh - 通过查看堆栈跟踪,似乎存在一些登录/身份验证问题(从日志中查找摘录)。 请检查 SQL Server 上的凭据/访问权限。

d__1.MoveNext()", "内部异常":{ "消息": "发生错误。 "异常消息": "用户登录失败。 "ExceptionType": "System.Data.SqlClient.SqlException", "StackTrace": " at

对于将来的引用,这通常是SQL Server错误,在接触代码之前,打开SQL Server Management Studio,看看您是否能够登录,很可能您不会登录。然后打开 SQL Server 配置管理器并确保服务器正在运行。

相关内容