-1

My project is an Asp.Net web site developed using visual studio 2015 (.Net framework: 4).

Its a WebApi and MVC two in one project and working fine on my development machine. But after publishing on another laptop and on smarterASP free hosting, I'm getting this error on pages that have Database calls (Entity Framework 6)

No connection could be made because the target machine actively refused it 127.0.0.1:27681

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

[SocketException (0x274d): No connection could be made because the target machine actively refused it 127.0.0.1:27681] System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) +6769080 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +249

[WebException: Unable to connect to the remote server] System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +606 System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) +64

[HttpRequestException: An error occurred while sending the request.] System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Lewisham.Controllers.d__1.MoveNext() +293 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97 System.Web.Mvc.Async.<>c__DisplayClass37.b__36(IAsyncResult asyncResult) +17 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +50 System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +225 System.Web.Mvc.Async.<>c__DisplayClass33.b__32(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 System.Web.Mvc.Async.<>c__DisplayClass2b.b__1c() +26 System.Web.Mvc.Async.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +12 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +22 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129

When I run the site on local with the DB Connection pointed to the remote DB it is working properly.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • ping the server from your command line. is it responding? may be you dont have enough permissions! – Neel Dec 04 '15 at 13:01
  • Use `telnet 127.0.0.1 27681`, probably this port is closed. – BWA Dec 04 '15 at 13:04
  • @Neel `request timed out` – Seevali Rathnayake Dec 04 '15 at 13:04
  • may be this would help : http://stackoverflow.com/questions/9695224/no-connection-could-be-made-because-the-target-machine-actively-refused-it-127-0 – Neel Dec 04 '15 at 13:06
  • Is the database supposed to be on the same remote host? If yes: does the remote host have a SQL server running / do you have access to it? if no: You should change the connection information to your database in the entity framework – Nick Otten Dec 04 '15 at 13:12
  • @Neel Thanks. I cannot do anything as the above answer suggest as its a free hosting. – Seevali Rathnayake Dec 04 '15 at 13:12
  • 1
    Looks like EF is still trying to connect to a local DB server. Have you configured it to connect to the remote database? If so, please include your connection string from web.config. – timothyclifford Dec 04 '15 at 13:22
  • Yep. Port is blocked. Especially with a free hosting provider, your use of ports is going to be extremely limited, probably just 80 and 443, actually. If you need to run something on a different port and be able to connect to it, you'll need a real hosting account, and most likely a full VM. – Chris Pratt Dec 04 '15 at 13:34

1 Answers1

0

The problem was, I didn't change the REST URL to match the hosting URL. That's why it didn't work on any machine rather than my development machine.

Thanks all for your contributions.