c# - 使用 WEB API 和 Entity Framework 项目的 IIS 本地计算机上的 "The underlying provider failed to Open"异常

标签 c# iis asp.net-web-api

我有一个与本地 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()\r\n   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection()\r\n   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)\r\n   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass49.<ExecuteFunction>b__47()\r\n   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)\r\n   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction(String functionName, ObjectParameter[] parameters)\r\n   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)\r\n   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)\r\n   at ServiceDBUtility.CommonFunctions.WriteLog(String USER_ID, Exception Ex, String reqURL)\r\n   at ServiceDBUtility.CommonFunctions.ThrowException(Exception e, HttpRequestMessage request, String customErrorMessage)\r\n   at LoginService.Controllers.LoginController.Login()\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   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)\r\n   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)\r\n   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)\r\n   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)\r\n   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)\r\n   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)\r\n   at System.Data.SqlClient.SqlConnection.Open()\r\n   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()\r\n   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)\r\n   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()"
  }
}

有人可以深入了解可能导致此错误的原因吗?

最佳答案

我就是这样解决这个问题的,

  1. 按 WIN + R
  2. 输入 inetmgr 然后回车
  3. 选择应用程序池
  4. 从右侧选择高级设置
  5. 转到“身份”并选择“自定义帐户”
  6. 提供事件目录的用户名和密码。

关于c# - 使用 WEB API 和 Entity Framework 项目的 IIS 本地计算机上的 "The underlying provider failed to Open"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37556942/

相关文章:

python - Win32com 代码无法在 IIS 上运行

html - 嵌入在 aspx 文件中的 @font-face 不起作用

javascript - 使用 nodatime 从时刻开始将时区传递到 web api 调用中

javascript - 仅当对象的属性发生更改时,Angular 才更新 View

asp.net-mvc - Angularjs 和 Web API CRUD 示例

c# - 将事件解决方案平台从任何 CPU 更改为 x86 时,WPF 应用程序未启动

c# - WPF 控件初始化的顺序 - IsEnabled

c# - 使用网络服务时文档移动错误

c# - 反转 ienumerable 的 lambda 函数

asp.net - 在本地主机上运行的 asp.net 应用程序上使用 https