Please help prevent refactoring the data level of this code and ODP.NET transactions.

I am using an Oracle 11g client with ODP.NET. I am trying to add conditional transaction processing.

Dim ds As New DataSet()
Dim txn As OracleTransaction
Dim _beginTransaction as Bolean = true
 Using conn As New OracleConnection(ConnString)
            Try
                conn.Open()
                If _beginTransaction Then
                        txn = conn.BeginTransaction(IsolationLevel.Serializable)
                End If

                Dim adapter As OracleDataAdapter = New OracleDataAdapter()
                adapter.SelectCommand = New OracleCommand(sSQL, conn)

                For i As Integer = 0 To UBound(parameters, 1)
                    adapter.SelectCommand.Parameters.Add(parameters(i))
                Next

                adapter.Fill(ds)
                If _beginTransaction Then
                    txn.Commit() //txn is undefined here? why?
                End If


            Catch e As Exception
                txn.Rollback()
            End Try
        End Using

How to set txn as nothing / null? Error: The variable "txn" is used before it is assigned a value. An exceptional link exception may occur at runtime. Links or pointers to solutions will also be appreciated.

:. RichardOD , , ODP.NET. , . , . , txn w/ if, try/catch .... ? ?

0
3

, _beginTransaction , true If _beginTransaction Then?

, ? Oracle BeingTransaction.

, . ?

- .NET? OracleConnection.BeginTransaction :

OracleConnection.BeginTransaction - .NET

0

: ? , ? , . conn , ...

0

Oracle . ?

:
vb oracle ( .net), , RichardOD. .

sql- sSQL. ​​ ​​DataAdapter, DataSet. SELECT. .

. ( CommandType - StoredProcedure). ref, DataSet. ?

Oracle does not need explicit transactions, as sql server does. Oracle starts an implicit transaction with the first dml operation in your session. Side effect - if you have not started a transaction, you cannot commit an implicit transaction. I do not know if there is access to the implicit transaction through the connection object.

0
source

All Articles