Npgsql.NpgsqlException: 'No password has been provided

.net-core c# entity-framework-core postgresql

Question

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.

1
0
12/13/2018 4:17:11 AM

Accepted Answer

You missed the semicolon between login and password in you connection string. Please see the example

1
12/13/2018 4:31:22 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow