0

I am getting 'The Underlining provider failed on Open' when calling one particular endpoint in the WebAPI using Angular's $resource to populate the dropdown lists. The form in the MVC View is like the following:

<div ng-app="myApp" ng-controller="myController as ctrl">
  <select ng-options="..." />
  <select ng-options="..." />
  <select ng-options="..." />
</div>

The MVC/Angular client front-end project has $resource configured in myApp.factory(). The WebAPI service project has only one controller with several endpoints. All methods use the same repository to retrieve data from SQL Server via a common Context object. When debugging the instance in VS2015, all methods return data correctly. When the project is published to the IIS Server, the troublesome endpoint would return data for several initial calls. Then it returns HTTP 500 error, saying 'The underlying provider failed on Open'. When the project is republished again, the endpoint works for several calls then Error 500 again. Does anyone know why? Thanks.

user266909
  • 1,841
  • 3
  • 32
  • 58
  • There isn't any Application error in the server log. – user266909 Oct 03 '16 at 05:03
  • Ok, one wild guess here. Are you using Owin startup class were you bind the webapi config? – Marcus Höglund Oct 03 '16 at 05:06
  • No. If I did, I commented out all the OWIN auth code generated by the WebAPI2 project. – user266909 Oct 03 '16 at 05:08
  • There are 4 GET methods in this MVC WebAPI controller. I use [Attribute routing] to decorate the additional methods so that they aren't set to respond to RESTful POST method. – user266909 Oct 03 '16 at 05:12
  • OK, But where do you bind the WebApiConfig to the HttpConfiguration? Could you share your Global.asax or, if you used Owin, the startup.cs class. Mayby you have them both in the project? – Marcus Höglund Oct 03 '16 at 05:20
  • The WebAPI is in a separate project and has no OWIN stuff. The MVC front-end project has OWIN stuff, but all lines in the Startup.cs are commented out. See the code attachment in the revised message. – user266909 Oct 03 '16 at 06:11
  • Looks like you are missing to bind the WebApiConfig.cs in the Global.asax. Add line: GlobalConfiguration.Configure(WebApiConfig.Register); at the last line in the application_start method in the global.asax – Marcus Höglund Oct 03 '16 at 06:41
  • Yes, there is a line for GlobalConfiguration.Configure(WebApiConfig.Register); Sorry that I miss copied the Global.asax from the WebAPI project. The correct one is attached in the revised message. – user266909 Oct 03 '16 at 07:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124811/discussion-between-user266909-and-marcus-h). – user266909 Oct 03 '16 at 15:44

1 Answers1

0

I think I may run into the problem of impersonated account doesn't flow from WebAPI to the Repository as mentioned in Impersonation and asynchrony in ASP.NET WebAPI.

All the methods in my repository are async methods. The IE brower debugger shows that {MachineName}$ is the account executes the query against the SQL Server, but the impersonation is enabled in the Web.config of the WebAPI project. I am not the server administrator of the IIS Server, so ASPNET.config on the IIS server, and changing the app pool account are not feasible. In addition, my application share the same app pool with many other applications. Here is the connectionstring and impersonate in my web.config:

    <add name="MyContext" connectionString="Data Source=SQLServerName;initial catalog=MyDatabaseName;integrated security=SSPI;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

    <identity impersonate="true" userName="myDomain\impersonatedAccount" password="thePassword" />
Community
  • 1
  • 1
user266909
  • 1,841
  • 3
  • 32
  • 58