插入使用Npgsql重复记录 [英] Inserting a duplicate record using Npgsql

查看:266
本文介绍了插入使用Npgsql重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将数据插入到使用Npgsql ADO.NET提供如下表:

I'm trying to insert data into the following table using the Npgsql ADO.NET provider:

CREATE SCHEMA core;

CREATE TABLE core.config(
    name TEXT NOT NULL,
    value TEXT NOT NULL,
    CONSTRAINT pk_config PRIMARY KEY (name)
);

第一插件工作正常,但如果我尝试再次插入具有相同名称的项目,Npgsql只是挂起。我希望抛出一个异常,说明该主键约束被侵犯,但Npgsql只是冻结代替。果然,当我检查服务器日志,我看到这样的:

The first insert works fine but if I try to insert an item with the same name again, Npgsql just hangs. I would expect an exception to be thrown stating that the primary key constraint has been violated, but Npgsql just freezes instead. Sure enough, if I check the server logs I see this:

重复键值违反唯一约束pk_config

但此消息似乎并没有被又回到了Npgsql。难道我做错了什么?我的code是在这里:

but this message doesn't seem to be getting back to Npgsql. Am I doing something wrong? My code is here:

using (NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=temp;User Id=postgres;Password=test1"))
{
    conn.Open();
    string cmdText = "INSERT INTO core.config(name, value) values ('item', 'value')";
    using (NpgsqlCommand cmd = new NpgsqlCommand(cmdText, conn))
    {
        cmd.ExecuteNonQuery(); // This works fine
        cmd.ExecuteNonQuery(); // Insert again: this hangs, but would expect an exception
    }
}

这是一个更大的应用程序(因此使用架构)的简化版本。然后我试图创建表的市民(不指定模式)。有趣的是这确实产生到第二次调用异常的ExecuteNonQuery()

This is a simplified version of a larger application (hence the use of a schema). I then tried creating the table in public (no schema specified). Interestingly this DOES generate an exception on the second call to ExecuteNonQuery():

后台发送无法识别的响应类型

我有点迷失,这是否是在Npgsql一个bug或者它是否是与架构权限(即使这个测试我使用了Postgres的超级用户)。

I'm a little lost as to whether this is a bug in Npgsql or whether it is something to do with Schema privileges (even though for this test I'm using the "postgres" superuser).

我使用Npgsql 2.0.12.0

I'm using Npgsql 2.0.12.0

推荐答案

我们有同样的问题。根据这一线索:

We have the same problem. According to this thread:

<一个href="http://pgfoundry.org/forum/forum.php?set=custom&forum_id=518&style=nested&max_rows=50&submit=Change+View" rel="nofollow">http://pgfoundry.org/forum/forum.php?set=custom&forum_id=518&style=nested&max_rows=50&submit=Change+View

我们只注意到Npgsql具有处理来自postgersql 9.3.x.错误消息时出现问题

We just noticed that Npgsql has a problem when handling error messages from postgersql 9.3.x.

格伦·帕克已经定格在我们的最新的code: https://github.com/ npgsql / Npgsql /拉/ 99 。我们正在努力创造一个新的2.0.12稳定版发布与此修复程序。

Glen Parker already fixed in our latest code: https://github.com/npgsql/Npgsql/pull/99. We are working to create a new 2.0.12 stable release with this fix.

。它是在beta测试阶段,虽然。

If you want to give it a try you can get the latest git code and check if it works ok for you. It is in beta state though.

请让我知道,如果你有任何问题了。

Please, let me know if you have any problems with it.

所以,如果你正在使用PostgreSQL 9.3,这可能是你的问题。你必须下载修订和实验,看看这实际上是在这种情况下,您的问题。

So if you are using PostgreSQL 9.3, this may be your issue. You'll have to download the fix and experiment to see if this is actually your issue in this case.

这篇关于插入使用Npgsql重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆