473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using oracle transactions in vb.net

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?

--

Regards,

Diego F.

May 22 '07 #1
2 14142
Diego F.,

This isn't really a problem with using oracle transactions. You are getting
a general warning that you might be trying to use a variable before it has
been assigned a value.

Of course, this is only a warning and if you are handling the transaction
variable correctly in the catch or finally block you can just ignore the
warning.

In the catch or finally block you should first test to see if the variable
has been assigned a value before trying to use it. Something like:

If trans IsNot Nothing Then ...

If you just don't like having the warning message show up, you can turn that
particular warning message off in the project's properties. On the Compile
tab, change the notification for use of variable prior to assignment from
warning to none.

Kerry Moorman

"Diego F." wrote:
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?

--

Regards,

Diego F.

May 22 '07 #2
On 22 mayo, 05:33, "Diego F." <diego_f...@msn.comwrote:
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?

--

Regards,

Diego F.
Hi,

I think put all inside try block is the best way. Any error occured
inside (fail to connect, failing executing query or transaction will
be catched and transaction will be reversed).

Any other opinion?

May 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: francis70 | last post by:
Hi, I have these 2 problem? Is there a way in Oracle to read UNCOMMITED data. i.e. in Oracle the normal behaviour is that a user's updates to a table are visible to other users ONLY when the...
3
by: none | last post by:
Hi. I'm implementing a web deployment using 9i. I have a table for STOCK, which has one or more PURCHASES, which have one or more PURCHASE_ITEMS. When a purchase item is INSERTED, I'd like the...
38
by: Mike | last post by:
No flame wars, please! We're planning a move from a non-relational system to a relational system. Our choices have been narrowed to Oracle and DB2. Since we're moving from non-relational to...
11
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
1
by: Rick | last post by:
I'm having problems with EnterpriseServices transactions running against Oracle 9iR2. I am inconsistently getting Oracle ORA-24761: Transaction Rolled Back results mid-transaction. If I start...
0
by: moko | last post by:
This is a bit long-winded. Can somebody read thru these 2 use cases, and tell me if it is feasible ? :- Use Case : Replication before Offline Synch Scenario 1 : Oracle Server , MSDE client ...
11
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
2
by: sajithamol | last post by:
I have an Oracle stored Procedure from which I will have to make call to few other SPs. My requirement is that the transactions in the subsequent SPs should be independent of the main transactions...
2
by: Ruslan A Dautkhanov | last post by:
Hello ! I'm about to install O9i on FreeBSD box. uname -a: FreeBSD stat2.scn.ru 5.2.1-RELEASE-p3 FreeBSD 5.2.1-RELEASE-p3 #2: Fri Apr 23 19:19:43 KRAST 2004...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.