简体   繁体   English

连接到 Redshift 集群时出错 - Npgsql.PostgresException: 28000: no pg_hba.conf entry for host

[英]Error connecting to Redshift Cluster - Npgsql.PostgresException: 28000: no pg_hba.conf entry for host

I am trying to connect to AWS Redshift from C# and perform a simple query:我正在尝试从 C# 连接到 AWS Redshift 并执行一个简单的查询:

public void GetData()
{
    NpgsqlConnectionStringBuilder builder = new NpgsqlConnectionStringBuilder();
    builder.Host = "myhostname";
    builder.Port = 5439;
    builder.Database = "mydb";
    builder.Username = "myusername";
    builder.Password = "mypassword";
    builder.ServerCompatibilityMode = ServerCompatibilityMode.Redshift;

    using (var conn = new NpgsqlConnection(builder.ConnectionString))
    {
        conn.Open();
        if (conn.State == ConnectionState.Open)
        {
            using (var cmd = new NpgsqlCommand())
            {
                cmd.Connection = conn;
                cmd.CommandText = "SELECT TOP 10 field FROM example;";

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetString(0));
                    }
                }
            }
        }
    }
}

When trying to make the connection I get: Npgsql.PostgresException: 28000: no pg_hba.conf entry for host .尝试建立连接时,我得到: Npgsql.PostgresException: 28000: no pg_hba.conf entry for host From the same machine I can connect to the cluster using JetBrains DataGrip using the same credentials.在同一台机器上,我可以使用 JetBrains DataGrip 使用相同的凭据连接到集群。

This question is almost the same, but instead of manually creating a connection string, your using the builder.这个问题几乎相同,但不是手动创建连接字符串,而是使用构建器。 So here is the code for that:所以这里是代码:

NpgsqlConnectionStringBuilder builder = new NpgsqlConnectionStringBuilder();
builder.TrustServerCertificate = true;
builder.SslMode = SslMode.Required;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 Npgsql 连接到 heroku 时出现“FATAL: No pg_hba.conf entry for host...” - Getting "FATAL: No pg_hba.conf entry for host..." when connecting to heroku through Npgsql 我收到此错误 28000:在 .Net Core 项目中应用迁移时主机“XXX.xx.xx.192”没有 pg_hba.conf 条目 - iam getting this error 28000: no pg_hba.conf entry for host "XXX.xx.xx.192" while applying migrations in .Net Core Project c#中的Postgresql Npgsql.PostgresException - Postgresql Npgsql.PostgresException in c# Npgsql.PostgresException 过程未找到异常 - Npgsql.PostgresException procedure not found exception Npgsql.PostgresException:关系“表名”不存在' - Npgsql.PostgresException: relation "tablename" does not exist' 尝试在 C# Winform 中查询 PostgreSQL 数据库时,ExecuteReader 出现 Npgsql.PostgresException 错误 - Npgsql.PostgresException error on ExecuteReader when attempting to query PostgreSQL database in C# Winform PostgreSQL:负载测试抛出错误 - Npgsql.PostgresException:“53300:抱歉,已经有太多客户端” - PostgreSQL: Load testing throws error - Npgsql.PostgresException: '53300: sorry, too many clients already' C#与SQLEditor — Npgsql.PostgresException 42703:“用户名”列不存在 - C# vs SQLEditor — Npgsql.PostgresException 42703: column “username” does not exist Npgsql.PostgresException:'55000:在此会话中尚未定义序列“ student_folio_id_seq”的当前时间” - Npgsql.PostgresException: '55000: currval of sequence “student_folio_id_seq” is not yet defined in this session' Npgsql.PostgresException (0x80004005): 42883: 运算符不存在: jsonb #> text - Npgsql.PostgresException (0x80004005): 42883: operator does not exist: jsonb #> text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM