我是 dotnet core、Entity framework core 和 PostgreSQL 的初學者。我在 ConfigureServices 方法中與數據庫建立連接,如下所示: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); }下面是我的控制器類如下:[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(); }}但我在控制器類的構造函數中收到錯誤,因為 Npgsql.NpgsqlException:'沒有提供密碼,但后端需要一個(在 MD5 中)'我已經搜索了 2 個小時,但在我的情況下沒有任何效果。有人建議我只需要在一個我已經在做的地方使用連接。無論如何,請建議我擺脫這個錯誤。
Npgsql.NpgsqlException: '沒有提供密碼
慕工程0101907
2022-06-12 14:45:06