asp.net web api: only during sql connection - HTTP 500 Error occurs : Local host is currently unable to handle request

て烟熏妆下的殇ゞ 提交于 2020-01-16 08:37:32

问题


The Web Api throws HTTP 500 error when it has to reference values from sql database. https://localhost:44304/api/values This works fine.

But, https://localhost:44304/api/User throws HTTP 500 Error - Local host is currently unable to handle request

The API is a simple test one, which has to retrieve data from User table in SQL database.

    private readonly string connectionString = 
    "Server=MyServerName\\SQLEXPRESS;Database=MyDatabase;Trusted_Connection=True;user 
    id=dbuser;password=dbuserpass;";

The data access file:

   namespace UserLogin.Models
   {
    public partial class User
    {
    public int UserId { get; set; }
    public string UserName { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    }
   }

No changes being done to any portions of the default code after creating the Web API Component.

Note: using udl, the test connection to the database was successful.

Thanks for help.

来源:https://stackoverflow.com/questions/59083428/asp-net-web-api-only-during-sql-connection-http-500-error-occurs-local-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!