c# - npgsql抛出错误的异常信息

标签 c# postgresql npgsql

我的数据库脚本如下。

CREATE TABLE books
(
    book_name national character varying(50) not null primary key
);

当我尝试使用 C# 编写代码时

private void button1_Click(object sender, EventArgs e)
{

    string sql = "INSERT INTO books(book_name) SELECT NULL;";
    string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
    using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
    {
        connection.Open();
        using (NpgsqlCommand npgsqlCommand = new NpgsqlCommand(sql, connection))
        {
            npgsqlCommand.ExecuteNonQuery();
        }
    }

}

它给了我这种类型的错误:

An unhandled exception of type 'System.NotSupportedException' occurred in Npgsql.dll

Additional information: Backend sent unrecognized response type: _

我知道我在 NOT NULL 列中传递了 NULL 值。我想得到确切的错误信息。上面的错误到底是什么意思?

最佳答案

我的最佳猜测:查看您的连接字符串。您可能在那里传递了一个不受支持的选项。使用 this page 仔细检查和交叉引用.

关于c# - npgsql抛出错误的异常信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21628073/

相关文章:

c# - 在asp.net core中设置HTTPGet调用的MaxURLLength

node.js - NodeJS 不那么明显的回调和更多的结构

mysql - 有什么方法可以将 Prometheus 数据存储到外部数据库,如 mysql 或 postgreSQL

sql - 如何创建查询以将列中的分割作为结果中的列?

c# - Entity Framework 6 - Npgsql - 连接字符串错误

c# - JQuery ajax 调用在 200 上执行错误

c# - 我应该如何在 C# 中实现我的存储库 (DDD) 以处理对同一聚合根的多个调用

c# - 多线程 Web 应用程序

c# - 邮件确认失败

postgresql - Npgsql 或您的 PostgreSQL 不支持类型 System.UInt32