问题
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