'已经有一个与此命令关联的打开的 DataReader 必须先关闭它' - Dataadapter.Update

问题描述

直到现在我只使用了没有这种问题的 Mssql Server,但现在我遇到了 MysqL Server 的问题。 我现在知道,MysqL 不支持 MARS(“多个活动结果集”),所以当我调用“Dataadapter.Update”时,我的多线程 VB.NET 服务出错。

我的数据库设计似乎不适合 MysqL,您有什么推荐的吗?

Module GlobalVariables
  Public eda As MysqLDataAdapter
  Public dda As MysqLDataAdapter
  Public dst As New ex___Service.ds
End Module

Public Sub Connect2Database(ByRef constr As String)
    'MysqL
    Dim con As New MysqLConnection(constr)
    con.open()
    eda = New MysqLDataAdapter("SELECT * FROM tbl1",con)
    dda = New MysqLDataAdapter("SELECT * FROM tbl2",con)

    Dim cb As MysqLCommandBuilder
    cb = New MysqLCommandBuilder(TryCast(eda,MysqLDataAdapter))
    eda.InsertCommand = cb.GetInsertCommand
    eda.DeleteCommand = cb.GetDeleteCommand
    eda.UpdateCommand = cb.GetUpdateCommand

    cb = New MysqLCommandBuilder(TryCast(dda,MysqLDataAdapter))
    dda.InsertCommand = cb.GetInsertCommand
    dda.DeleteCommand = cb.GetDeleteCommand
    dda.UpdateCommand = cb.GetUpdateCommand

    con.Close()

    GetData()
End Sub

Public Sub GetData()
    eda.Fill(dst.tbl1)
    dda.Fill(dst.tbl1)
End Sub

后来我在多线程环境中调用了一些:

eda.Update(dst.tbl1)

并得到异常:

已经有一个与此命令关联的打开的 DataReader 必须先关闭

是否有选项可以检查是否另一个线程使用更新写入数据库?或者检查连接是否打开?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...