【问题标题】:VB net and postgres : Getting "An operation is already in progress" using npgsqlVB net 和 postgres:使用 npgsql 获取“操作已在进行中”
【发布时间】:2016-09-27 00:35:52
【问题描述】:

我正在使用以下代码检索对象(产品)列表和其中的另一个列表(尺寸)。

Dim l As New List(Of Entidades.producto)

Dim c As New NpgsqlCommand("select id, name from product", cn)
Dim r As NpgsqlDataReader = c.ExecuteReader

Do While r.Read

    Dim p As New Entidades.product
    p.ID = r.Item("id")
    p.name = r.Item("name")
    l.Add(p)

    >>> I HAD THE OTHER LOOP HERE BUT HAVING THE SAME ISSUE TRIED TO PUT THE
    READER OUTSIDE OF THIS LOOP.

Loop

r.Close()

For Each p In l
    c = New NpgsqlCommand("select t.id id, t.name nombre from productsize pt join size t on t.id = pt.sizeid where productid = :productid order by ord", cn)
    c.Parameters.AddWithValue("productid", pgsqlTypes.NpgsqlDbType.Integer, p.ID)
    c.Prepare() <---- HERE I GET THE ERROR

    Dim rt As NpgsqlDataReader = c.ExecuteReader

    Do While rt.Read

        Dim t As New size
        t.ID = rt.Item("id")
        t.nombre = rt.Item("name")
        p.size.Add(t)

    Loop

Next


Return l

我在执行准备时收到“操作已在进行中”错误。

我认为关闭阅读器就足够了,我可以运行另一个阅读器。

【问题讨论】:

  • 我不知道 Postgres,但我会检查提供程序是否支持连接字符串中的 MultipleActiveResultSets=True 配置设置。在这种情况下,您不再需要两个循环,并且可以在为第一个读者提供服务时重用连接

标签: vb.net postgresql visual-studio-2013 npgsql


【解决方案1】:

第二个循环没有关闭阅读器,当我再次调用该函数时,它爆炸了。

【讨论】:

    猜你喜欢
    • 2016-04-05
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多