我试图在Oracle数据库中的表上运行插入查询。 以下是我正在进行的测试。
首先锁定我想从SQL Developer会话中插入的表
lock table RANDOM_TABLE in exclusive mode nowait
即使在完成60秒后控件也没有返回,但是当我解锁表时,它正在执行插入操作并且还会抛出异常。
我认为,当命令超时到期时,.NET正在抛出异常,但是在表解锁之前,控制没有从本机代码返回。在这种情况下如何避免无限期等待?
Public Shared Function ExecuteNonQuery(ByVal ConnectionString As String, ByVal factory As DbProviderFactory, ByVal sql As String) As Integer
Dim rowsAffected As Integer = -1
Using conn As DbConnection = factory.CreateConnection
conn.ConnectionString = ConnectionString
conn.Open()
If conn.State.Equals(ConnectionState.Open) Then
Try
'This works
Dim command As DbCommand = conn.CreateCommand
command.CommandText = sql
command.CommandType = CommandType.Text
command.CommandTimeout = 60
'**********This blocks and never returns.
rowsAffected = command.ExecuteNonQuery()
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End If
End Using
Return rowsAffected
End Function