使用EfCore通过Internet连接到PostgreSQL数据库

时间:2018-10-09 13:17:16

标签: c# proxy ef-core-2.1

我坐在WiFi上的代理(HTTPS代理)后面。当我尝试通过EfCore连接到数据库时,出现以下异常:System.TimeoutException: 'The operation has timed out.'。因此,我需要一种方法来告诉EfCore我的代理凭据(代理主机,代理端口,代理密码,代理用户名)。

注意:如果我使用手机上的热点或其他WiFi,那么效果很好。

这是我的DbContext类现在的样子:

public class SchoolDayContext : DbContext
{
    public DbSet<SchoolDay> SchoolDays { get; set; }

    public SchoolDayContext()
    {
        this.Database.EnsureCreated();
    }

    protected override void OnConfiguring(DbContextOptionsBuilder options)
    {
        options.UseNpgsql($"Server=; Port=; User Id=; Password=; Database=;");
    }
}
public class SchoolDay
{
    [Key]
    public int Id { get; set; }
    public DateTime Date { get; set; }
    public DateTime CreationDate { get; set; }
    public string Header { get; set; }
    public string Content { get; set; }
}

0 个答案:

没有答案