我有错误无效的操作

我有错误无效的操作

本文介绍了我应该怎么做?我有错误无效的操作。连接已关闭。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有错误无效的操作。连接已关闭。当我使用功能ExecuteData。



请指教。我该怎么办?



I have error Invalid operation. The connection is closed. when i use function ExecuteData.

Please advise. How should I do?

Private Shared Conn As New OracleConnection
    Private Shared Trans As OracleTransaction
 
    Private Shared Sub OpenConnect(ByVal strConnectionString As String)
        With Conn
            If .State = ConnectionState.Open Then .Close()
            .ConnectionString = strConnectionString
            .Open()
        End With
    End Sub
 
    Private Shared Sub CloseConnect()
        Conn.Close()
        Conn.Dispose()
    End Sub
 
    Public Overloads Shared Function ExecuteData(ByVal strCommandText As String, _
                                             ByVal ParameterCollection As OracleParameterCollection, _
                                             Optional ByVal strConnectionString As String = "") As ExecuteReturn
        If Conn.State = ConnectionState.Closed Then OpenConnect(strConnectionString)
        Dim oraCommand As New OracleCommand
        oraCommand.CommandText = strCommandText
        oraCommand.Connection = Conn
        If Not Trans Is Nothing Then
            oraCommand.Transaction = Trans
        End If
        Dim oraParam As OracleParameterCollection = ParameterCollection
        For Each param As OracleParameter In ParameterCollection
            oraCommand.Parameters.Add(param.ParameterName, param.OracleType).Value = param.Value
        Next
        Dim effect As New ExecuteReturn
        Try
            effect.intRowEffected = oraCommand.ExecuteNonQuery()
            If oraCommand.Transaction Is Nothing Then
                CloseConnect()
            End If
            Return effect
        Catch ex As Exception
            effect.intRowEffected = -1
            effect.strErrorMessage = ex.Message
            CloseConnect()
            Return effect
        End Try
    End Function

推荐答案


这篇关于我应该怎么做?我有错误无效的操作。连接已关闭。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 20:27