由于对象的当前状态,VB.net Oracle 操作无效
好吧,我真的需要找到一种方法来通过字符串来完成此操作,而不是使用更新查询来完成所有操作。
Dim theXMLCode As OracleClob
Dim OracleConnection2 As New OracleConnection()
Dim dr2 As OracleDataReader
Dim holdXML As String = ""
Public Function connectToOracleDB2() As Boolean
OracleConnection2.ConnectionString = "User Id=" & dbUserId & ";Password=" & dbPassword & ";Data Source=(DESCRIPTION=(ADDRESS_LIST=" & _
"(ADDRESS=(PROTOCOL=TCP)(HOST=" & dbHost & ")(PORT=" & dbPort & ")))" & _
"(CONNECT_DATA=(SERVICE_NAME=" & dbServiceName & ")))"
Try
OracleConnection2.Open()
Return True
Catch ee As Exception
OracleConnection2.Close()
Return False
End Try
End Function
Dim strSQL = "UPDATE CSR.TARGET ces " & _
"SET (STATUS_CODE, COMPLETE_DATE, DATA) = " & _
"(SELECT 'ERROR', '', (:XML_DATA) " & _
"FROM CSR.SOURCE C " & _
"WHERE (c.EID = ces.EID) " & _
"AND c.STATUS_CODE = 'ERROR') " & _
"WHERE EXISTS (SELECT 1 " & _
"FROM CSR.SOURCE C " & _
"WHERE (c.EID = ces.EID) " & _
"AND c.STATUS_CODE = 'ERROR')"
Try
Dim parmData As New OracleParameter
With parmData
.Direction = ParameterDirection.Input
.OracleDbType = OracleDbType.Clob
.ParameterName = "XML_DATA"
.Value = holdXML
End With
OracleCommand2.Parameters.Add(parmData)
OracleCommand2.CommandText = strSQL
OracleCommand2.ExecuteNonQuery()
但我收到错误:
错误:由于对象的当前状态,操作无效。
在线:
OracleCommand2.ExecuteNonQuery()
任何帮助都会让这个东西正常工作:o)
David
Ok, i am really in need of finding a way to do this via a string to clob instead of using the update query to to do all.
Dim theXMLCode As OracleClob
Dim OracleConnection2 As New OracleConnection()
Dim dr2 As OracleDataReader
Dim holdXML As String = ""
Public Function connectToOracleDB2() As Boolean
OracleConnection2.ConnectionString = "User Id=" & dbUserId & ";Password=" & dbPassword & ";Data Source=(DESCRIPTION=(ADDRESS_LIST=" & _
"(ADDRESS=(PROTOCOL=TCP)(HOST=" & dbHost & ")(PORT=" & dbPort & ")))" & _
"(CONNECT_DATA=(SERVICE_NAME=" & dbServiceName & ")))"
Try
OracleConnection2.Open()
Return True
Catch ee As Exception
OracleConnection2.Close()
Return False
End Try
End Function
Dim strSQL = "UPDATE CSR.TARGET ces " & _
"SET (STATUS_CODE, COMPLETE_DATE, DATA) = " & _
"(SELECT 'ERROR', '', (:XML_DATA) " & _
"FROM CSR.SOURCE C " & _
"WHERE (c.EID = ces.EID) " & _
"AND c.STATUS_CODE = 'ERROR') " & _
"WHERE EXISTS (SELECT 1 " & _
"FROM CSR.SOURCE C " & _
"WHERE (c.EID = ces.EID) " & _
"AND c.STATUS_CODE = 'ERROR')"
Try
Dim parmData As New OracleParameter
With parmData
.Direction = ParameterDirection.Input
.OracleDbType = OracleDbType.Clob
.ParameterName = "XML_DATA"
.Value = holdXML
End With
OracleCommand2.Parameters.Add(parmData)
OracleCommand2.CommandText = strSQL
OracleCommand2.ExecuteNonQuery()
But i get the error:
ERROR: Operation is not valid due to the current state of the object.
On the line:
OracleCommand2.ExecuteNonQuery()
Any help would be great to get this thing working :o)
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您找不到创建临时 lob 指针的示例,因此这里是使用以前项目中的 Microsoft Enterprise Library 的 C# 示例。此示例与存储过程交互,但使用 SQL 更新和 BLOB/CLOB 时的方法相同:
Since you could not find an example of creating a temporary lob pointer, here is an example in C# using the Microsoft Enterprise Library from a previous project. This example interfaces with a stored procedure, but is the same approach when using a SQL update and BLOB/CLOB:
一般来说,您会得到如下所示的内容:
重要:此代码是凌乱的徒手代码。我不再那么熟悉 VB 语法,但在 C# 中,您可以在
using
语句的声明中实例化OracleConnection
对象。如果 VB 中没有这样的东西(尽管我怀疑有),那么您可以将其包装在 try/catch/finally 中,以确保连接正确关闭并且对象正确处置。Generally, you'd have something like this:
Important: This code is messy free-hand code. I'm not all that familiar with VB syntax anymore, but in C# you'd instantiate the
OracleConnection
object inside the declaration of ausing
statement. If there's no such thing in VB (though I suspect there is) then you'd wrap it in a try/catch/finally to make sure the connection is properly closed and the object(s) properly disposed.