I am a beginner in dotnet core, Entity framework core, and PostgreSQL. I am making a connection with the database in ConfigureServices method as follows:
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
string databaseConnection = "Server=localhost;Port=5432;Database=EF_Lesson Username=postgres password=123;Integrated Security=false;";
services.AddDbContext<EF_LessonContext>(
options => options.UseNpgsql(databaseConnection));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
Below is my Controller class as follows:
[Route("ToLesson")]
[ApiController]
public class EF_LessonController : ControllerBase
{
private readonly EF_LessonContext _context;
public EF_LessonController(EF_LessonContext context)
{
_context = context;
if (_context.Webserverlogin.Count() == 0)
{
_context.Webserverlogin.Add(new Webserverlogin() { });
_context.SaveChanges();
}
}
[HttpGet]
public ActionResult<List<Webserverlogin>> GetAll()
{
return _context.Webserverlogin.ToList();
}
}
but I am getting an error in the constructor of controller class as Npgsql.NpgsqlException: 'No password has been provided but the backend requires one (in MD5)'
I have searched for 2 hours and nothing works in my case. Someone suggested that I need to use a connection in only one place which I was already doing.
Please suggest me anyway to get rid of this error.