通过.NET mvc连接到Oracle DB

时间:2017-02-15 22:38:11

标签: c# asp.net-mvc oracle rest

我将我的C#MVC API连接到Oracle,但是当我运行API并测试它时,我得到了以下错误。我检查了.NET引用并安装了Oracle.Data.Access,此外我删除了它并重新安装了Oracle.Data.Access,但同样的错误仍然存​​在。这可能是什么?

 {
 "Message": "An error has occurred.",
 "ExceptionMessage": "ORA-12170: TNS:Connect timeout occurred",
 "ExceptionType": "Oracle.DataAccess.Client.OracleException",
 "StackTrace": "   at         Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)\r\n   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)\r\n   at Oracle.DataAccess.Client.OracleConnection.Open()\r\n   at MRF_API.Controllers.ItemController.Get(String searchdesc) in C:\\Users\\nevinj\\Documents\\Visual Studio 2015\\Projects\\MRF_API\\MRF_API\\Controllers\\ItemController.cs:line 88\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.ActionExecutor.Execute(Object instance, Object[] arguments)\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.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()"
  }

1 个答案:

答案 0 :(得分:1)

此时您必须分析的实际问题是 ORA-12170:TNS:发生连接超时

你会在网上发现有很多理由可能会触发这个错误,但你可能要检查的第一件事就是确保你的连接字符串/ TNS条目设置正确。

尝试使用同一台计算机上的相同连接字符串,但使用另一个客户端(例如sqlplus)并查看是否有效(确认数据库已启动且可从客户端计算机访问)。