【问题标题】:Web service with .net does not connect to mysql db in interner information service使用 .net 的 Web 服务未连接到 Internet 信息服务中的 mysql db
【发布时间】:2019-03-10 19:28:11
【问题描述】:

我已经编写了一个连接到 mysql 数据库并提供 api 的 web 服务。当我在 Visual Studio 中运行它时,它工作正常。现在我希望它在我把它放在互联网信息服务中时工作。但是 api 没有返回。我期望此 api 运行的单页应用程序给了我以下错误

 GET http://localhost:8024/api/Interviewee 500 (Internal Server Error)


angular.js:15536 Possibly unhandled rejection: {"data":{"Message":"An error has occurred.","ExceptionMessage":"Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.","ExceptionType":"System.InvalidOperationException","StackTrace":"   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 IntervieweeService.Controllers.IntervieweeController.GetInterviewees() in C:\\Projects\\IntervieweeApp\\IntervieweeService\\IntervieweeService\\Controllers\\IntervieweeController.cs:line 30\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_1.<GetExecutor>b__3(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.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"},"status":500,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"http://localhost:8024/api/Interviewee","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"Internal Server Error","xhrStatus":"complete"}
(anonymous) @ angular.js:15536
(anonymous) @ angular.js:11815
processChecks @ angular.js:17946
$digest @ angular.js:19075
$apply @ angular.js:19463
done @ angular.js:13312
completeRequest @ angular.js:13569
requestLoaded @ angular.js:13474
load (async)
(anonymous) @ angular.js:13457
sendReq @ angular.js:13257
serverRequest @ angular.js:12998
processQueue @ angular.js:17914
(anonymous) @ angular.js:17962
$digest @ angular.js:19075
$apply @ angular.js:19463
done @ angular.js:13312
completeRequest @ angular.js:13569
requestLoaded @ angular.js:13474
load (async)
(anonymous) @ angular.js:13457
sendReq @ angular.js:13257
serverRequest @ angular.js:12998
processQueue @ angular.js:17914
(anonymous) @ angular.js:17962
$digest @ angular.js:19075
$apply @ angular.js:19463
bootstrapApply @ angular.js:1945
invoke @ angular.js:5122
doBootstrap @ angular.js:1943
bootstrap @ angular.js:1963
angularInit @ angular.js:1848
(anonymous) @ angular.js:36216
fire @ jquery-2.2.4.js:3187
fireWith @ jquery-2.2.4.js:3317
ready @ jquery-2.2.4.js:3536
completed @ jquery-2.2.4.js:3552

连接字符串

Server=localhost;Port=8024;Database=intervieweedb;Uid=rrrr;Pwd=111;

我怎样才能做到这一点?谢谢

【问题讨论】:

  • 你已经调试了吗? 500 很笼统,你能提供实际的错误吗?
  • 你的连接字符串是什么样子的?您没有在响应正文中获得任何详细信息吗?您应该会看到抛出的异常的堆栈跟踪。
  • 我添加了完整的错误和连接字符串
  • 根据.net连接器的文档,连接字符串中有相当多的微调参数。您确定您在代码中正确处理了所有未使用的连接吗? IIS 正在管理应用程序池,这意味着您可能会唤醒许多可以轻松消耗连接池的实例。
  • 连接字符串中的端口错误。如果您通过http://localhost:8024/api/Interviewee 访问您的网站,那么您的网络服务器正在使用端口 8024。连接字符串中的"Server=localhost;Port=8024" 一定是错误的,因为 MySQL 需要在不同的端口上运行。

标签: c# mysql .net web-services iis


【解决方案1】:

如果您通过http://localhost:8024/api/Interviewee 访问您的网站,那么您的网络服务器正在使用端口 8024。您的连接字符串中的Server=localhost;Port=8024 错误,因为 MySQL 需要在不同的端口上运行。

将 MySQL 连接字符串中的 Port 更改为 MySQL 服务器的端口号(通常为 3306)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-23
    • 2011-10-11
    • 1970-01-01
    • 2017-05-27
    • 2023-03-22
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多