D
Diego F.
Hello. I'm writing some code to connect and execute queries using oracle
namespace in VB.NET.
My question is about the use of transactions. To use oracle transactions, I
must do something like:
Dim con As New OracleConnection(_conString)
Dim cmd As New OracleCommand(query, con)
cmd.CommandType = CommandType.Text
con.Open()
Dim trans As OracleTransaction = con.BeginTransaction()
But I'm used to do con.Open inside a try catch statement. If I do that, and
put the BeginTransaction inside the try, I get a null reference warning in
the catch, where I do trans.rollback.
Now I have that:
Dim con As New OracleConnection(_conString)
Dim cmd As New OracleCommand(query, con)
cmd.CommandType = CommandType.Text
con.Open()
Dim trans As OracleTransaction = con.BeginTransaction()
Try
cmd.ExecuteNonQuery()
trans.Commit()
Catch e As Exception
trans.Rollback()
End Try
But I don't like the con.Open before the try block. What is the best way to
do that?
namespace in VB.NET.
My question is about the use of transactions. To use oracle transactions, I
must do something like:
Dim con As New OracleConnection(_conString)
Dim cmd As New OracleCommand(query, con)
cmd.CommandType = CommandType.Text
con.Open()
Dim trans As OracleTransaction = con.BeginTransaction()
But I'm used to do con.Open inside a try catch statement. If I do that, and
put the BeginTransaction inside the try, I get a null reference warning in
the catch, where I do trans.rollback.
Now I have that:
Dim con As New OracleConnection(_conString)
Dim cmd As New OracleCommand(query, con)
cmd.CommandType = CommandType.Text
con.Open()
Dim trans As OracleTransaction = con.BeginTransaction()
Try
cmd.ExecuteNonQuery()
trans.Commit()
Catch e As Exception
trans.Rollback()
End Try
But I don't like the con.Open before the try block. What is the best way to
do that?