VB.net更新Oracle记录ExecuteNonQuery问题

发布于 2024-10-23 17:47:04 字数 2208 浏览 11 评论 0原文

大家好,当我使用 TOAD 更新表时,使用此查询时一切正常:

Update CSR.CSR_EAI_SOURCE ces 
        Set (STATUS_CODE, COMPLETE_DATE, DATA) =
            (SELECT 'ERROR', '', REPLACE(REPLACE(c.Data, '…', ' '), '’','''') 
             FROM CSR.CSR_EAI_SOURCE C
             WHERE c.EID = ces.EID
               AND c.STATUS_CODE = 'ERROR')
        WHERE EXISTS (SELECT 1
                       FROM CSR.CSR_EAI_SOURCE C
                       WHERE c.EID = ces.EID
                         AND c.STATUS_CODE = 'ERROR');

但是,一旦我尝试使用此代码在 VB.net 程序中执行相同的操作:

 Dim OracleCommand As New OracleCommand()
 Dim ra As Integer

 OracleCommand = New OracleCommand("UPDATE   CSR.CSR_EAI_SOURCE ces " & _
                                      "SET      (STATUS_CODE, COMPLETE_DATE, DATA) = " & _
                                                "(SELECT    'ERROR', '', REPLACE(REPLACE(c.Data, '…', ' ' ), '’','''') " & _
                                                "FROM       CSR.CSR_EAI_SOURCE C " & _
                                                "WHERE      (c.EID = ces.EID) " & _
                                                "AND        c.STATUS_CODE = 'ERROR') " & _
                                      "WHERE    EXISTS (SELECT 1 " & _
                                      "FROM     CSR.CSR_EAI_SOURCE C " & _
                                      "WHERE    (c.EID = ces.EID) " & _
                                      "AND      c.STATUS_CODE = 'ERROR')", OracleConnection)

  Try
      ra = OracleCommand.ExecuteNonQuery()
      OracleConnection.Close()
      MsgBox("done")
  Catch ex As Exception
      MsgBox("ERROR: " & Err.Description & " " & Err.Number)
      OracleConnection.Close()
  End Try

它保留在 ra = OracleCommand.ExecuteNonQuery 上() 连续直到出现错误

CLR 在 60 秒内无法从 COM 上下文 0x3327fa8 转换到 COM 上下文 0x3328118。拥有目标上下文/单元的线程很可能执行非泵送等待或处理非常长时间运行的操作而不泵送 Windows 消息。这种情况通常会对性能产生负面影响,甚至可能导致应用程序变得无响应或内存使用量随着时间的推移不断累积。为了避免此问题,所有单线程单元 (STA) 线程都应使用泵送等待原语(例如 CoWaitForMultipleHandles),并在长时间运行的操作期间定期泵送消息。

我该怎么做才能让它在 VB.net 中工作,因为它在运行相同的查询时在 TOAD 中工作得很好?

谢谢!

大卫

Hey all when i use TOAD to update a table all works just fine when using this query:

Update CSR.CSR_EAI_SOURCE ces 
        Set (STATUS_CODE, COMPLETE_DATE, DATA) =
            (SELECT 'ERROR', '', REPLACE(REPLACE(c.Data, '…', ' '), '’','''') 
             FROM CSR.CSR_EAI_SOURCE C
             WHERE c.EID = ces.EID
               AND c.STATUS_CODE = 'ERROR')
        WHERE EXISTS (SELECT 1
                       FROM CSR.CSR_EAI_SOURCE C
                       WHERE c.EID = ces.EID
                         AND c.STATUS_CODE = 'ERROR');

However, once i try doing the same thing in my VB.net program using this code:

 Dim OracleCommand As New OracleCommand()
 Dim ra As Integer

 OracleCommand = New OracleCommand("UPDATE   CSR.CSR_EAI_SOURCE ces " & _
                                      "SET      (STATUS_CODE, COMPLETE_DATE, DATA) = " & _
                                                "(SELECT    'ERROR', '', REPLACE(REPLACE(c.Data, '…', ' ' ), '’','''') " & _
                                                "FROM       CSR.CSR_EAI_SOURCE C " & _
                                                "WHERE      (c.EID = ces.EID) " & _
                                                "AND        c.STATUS_CODE = 'ERROR') " & _
                                      "WHERE    EXISTS (SELECT 1 " & _
                                      "FROM     CSR.CSR_EAI_SOURCE C " & _
                                      "WHERE    (c.EID = ces.EID) " & _
                                      "AND      c.STATUS_CODE = 'ERROR')", OracleConnection)

  Try
      ra = OracleCommand.ExecuteNonQuery()
      OracleConnection.Close()
      MsgBox("done")
  Catch ex As Exception
      MsgBox("ERROR: " & Err.Description & " " & Err.Number)
      OracleConnection.Close()
  End Try

It stays on the ra = OracleCommand.ExecuteNonQuery() continuously until i get the error

The CLR has been unable to transition from COM context 0x3327fa8 to COM context 0x3328118 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

What could i do in order to get this working within VB.net since it works just fine in TOAD when running that same query?

Thanks!

David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫负雪 2024-10-30 17:47:04

您还可以关闭检测到 ContextSwitchDeadlock 异常:

为了避免这些错误弹出窗口
出现时,选择例外
Visual Studio 窗口中的调试菜单
并在异常对话框中选择
托管调试助手
异常节点。然后选择
ContextSwitch死锁并移除
从“抛出”列中选择

http:// 的 dotnetdud.blogspot.com/2009/01/clr-has-been-unable-to-transition-from.html

编辑:检查锁

SELECT LPAD(' ',DECODE(l.xidusn,0,3,0)) || l.oracle_username "User Name",
o.owner, o.object_name, o.object_type
FROM v$locked_object l, dba_objects o
WHERE l.object_id = o.object_id
ORDER BY o.object_id, 1 desc;

请注意,您需要能够查看 dba_objects以及 v$locked_object (从 此处 提取此内容) )

并查看这篇文章
http://www.orafaq.com/node/854

you can also turn off that ContextSwitchDeadlock was detected exception:

To avoid these error popups from
appearing, select Exceptions from the
Debug menu from Visual Studio window
and in the Exception Dialog box select
the Managed Debugging Assistants
Exception Node. Then select
ContextSwitchDeadlock and remove the
select from Thrown column

from http://dotnetdud.blogspot.com/2009/01/clr-has-been-unable-to-transition-from.html

EDIT:Check for Locks

SELECT LPAD(' ',DECODE(l.xidusn,0,3,0)) || l.oracle_username "User Name",
o.owner, o.object_name, o.object_type
FROM v$locked_object l, dba_objects o
WHERE l.object_id = o.object_id
ORDER BY o.object_id, 1 desc;

do note you will need ability to see dba_objects as well as v$locked_object (pulled this from here)

and check out this article
http://www.orafaq.com/node/854

梦屿孤独相伴 2024-10-30 17:47:04

看起来查询需要很长时间才能执行,因此 UI 被阻塞。最好的解决方案是在不同的线程中运行此查询,这样它就不会阻塞 UI...或优化您的查询以使其运行得更快。

Looks like the query takes a very long time to execute, so the UI is blocking. The best solution would be to run this query in a different thread, so that it doesn't block the UI... or optimize your query so that it runs faster.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文