473,598 Members | 3,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Oracle read only transaction in VB .NET?

I am attempting to write a program with VB 2005 Express Edition which
accesses an Oracle 9 database and dumps the results of three SELECT
queries into a spreadsheet file once every hour.

Modifications will be being made to the database whilst this program is
running. I would like the three queries to each give data relating to
the same point in time, despite the fact they actually run in sequence.

In Oracle's sqlplus tool, I can use "SET TRANSACTION READ ONLY" to give
transaction-level read consistency. Oracle describe it this way: "All
subsequent queries in that transaction only see changes committed
before the transaction began. Read-only transactions are useful for
reports that run multiple queries against one or more tables while
other users update these same tables".

This seems to be exactly what I need. I'm thinking that the structure
I want is something like the below (I think the detail of the SELECT
queries doesn't matter):

SET TRANSACTION READ ONLY;
SELECT * FROM A;
SELECT * FROM B;
SELECT * FROM C;
COMMIT;

I've tested this with sqlplus, and if I modify the tables whilst the
transaction is in progress, the results show the state as it was when
the transaction began :) (Conversely, if I don't use a transaction,
intermediate modifications between the queries do have an effect.)

Unfortunately I can't get anything similar to work in Visual Basic
..NET. I have tried adding code something like the following before
some code that does two test queries with a pause in between, but the
SET TRANSACTION READ ONLY seems to have no effect. (Apologies for not
providing full code here.)

dbConnection.Op en()
dbCommand = dbConnection.Cr eateCommand()
dbCommand.Comma ndText = "SET TRANSACTION READ ONLY"
dbCommand.Execu teNonQuery()

I assume the SET TRANSACTION READ ONLY is being optimised away, or
perhaps changes made to the connection in this way aren't persistent.

I have also tried something along the lines of:

dbConnection.Op en()
dbTransaction = dbConnection.Be ginTransaction( IsolationLevel. Snapshot)
dbCommand.Trans action = dbTransaction

because the description of IsolationLevel. Snapshot seems to be closest
to what I want. But with this, I get "Invalid IsolationLevel
parameter: must be ReadCommitted or Serializable." I assume
IsolationLevel. Snapshot just isn't implemented in
System.Data.Ora cleClient :(

Am I approaching this in the wrong way? Perhaps I need to work at a
lower level, eg ODBC?

I am a beginner at VB.NET. However I have a lot of experience in C,
Java, Apache+PHP+mysq l and some experience in VB6.

Any help much appreciated.

Ashley.

Jun 19 '06 #1
5 7538
Hi ashley,

have you made sure you send the 5 commands in sequence - without
closing
the connection - between a command and the following one?

-tom

as*********@gma il.com ha scritto:
I am attempting to write a program with VB 2005 Express Edition which
accesses an Oracle 9 database and dumps the results of three SELECT
queries into a spreadsheet file once every hour.

Modifications will be being made to the database whilst this program is
running. I would like the three queries to each give data relating to
the same point in time, despite the fact they actually run in sequence.

In Oracle's sqlplus tool, I can use "SET TRANSACTION READ ONLY" to give
transaction-level read consistency. Oracle describe it this way: "All
subsequent queries in that transaction only see changes committed
before the transaction began. Read-only transactions are useful for
reports that run multiple queries against one or more tables while
other users update these same tables".

This seems to be exactly what I need. I'm thinking that the structure
I want is something like the below (I think the detail of the SELECT
queries doesn't matter):

SET TRANSACTION READ ONLY;
SELECT * FROM A;
SELECT * FROM B;
SELECT * FROM C;
COMMIT;

I've tested this with sqlplus, and if I modify the tables whilst the
transaction is in progress, the results show the state as it was when
the transaction began :) (Conversely, if I don't use a transaction,
intermediate modifications between the queries do have an effect.)

Unfortunately I can't get anything similar to work in Visual Basic
.NET. I have tried adding code something like the following before
some code that does two test queries with a pause in between, but the
SET TRANSACTION READ ONLY seems to have no effect. (Apologies for not
providing full code here.)

dbConnection.Op en()
dbCommand = dbConnection.Cr eateCommand()
dbCommand.Comma ndText = "SET TRANSACTION READ ONLY"
dbCommand.Execu teNonQuery()

I assume the SET TRANSACTION READ ONLY is being optimised away, or
perhaps changes made to the connection in this way aren't persistent.

I have also tried something along the lines of:

dbConnection.Op en()
dbTransaction = dbConnection.Be ginTransaction( IsolationLevel. Snapshot)
dbCommand.Trans action = dbTransaction

because the description of IsolationLevel. Snapshot seems to be closest
to what I want. But with this, I get "Invalid IsolationLevel
parameter: must be ReadCommitted or Serializable." I assume
IsolationLevel. Snapshot just isn't implemented in
System.Data.Ora cleClient :(

Am I approaching this in the wrong way? Perhaps I need to work at a
lower level, eg ODBC?

I am a beginner at VB.NET. However I have a lot of experience in C,
Java, Apache+PHP+mysq l and some experience in VB6.

Any help much appreciated.

Ashley.


Jun 19 '06 #2
to************* *@uniroma1.it wrote:
have you made sure you send the 5 commands in sequence - without closing
the connection - between a command and the following one?


Hi tom...

Thanks for the reply. I don't think I've closed the connection. Here
is the complete code (this is a Console application, by the way):

Imports System.Data.Ora cleClient ' for this to work, need to have
System.Data.Ora cleClient listed as a reference in the project
properties...

Module Module1

Sub Main()

Dim dbConnectionStr ing As String = "Password=ASHLE Y;User
ID=ASHLEY;Data Source=HAGRID"
Dim queryString As String = "SELECT * FROM TEST"

Dim dbConnection As OracleConnectio n
Dim dbCommand As OracleCommand
Dim dbDataReader As OracleDataReade r

Try
dbConnection = New OracleConnectio n(dbConnectionS tring)
dbConnection.Op en()

dbCommand = dbConnection.Cr eateCommand()
dbCommand.Comma ndText = "SET TRANSACTION READ ONLY NAME
'PDI_HSD'"
dbCommand.Execu teNonQuery()

dbCommand.Comma ndText = queryString

Console.WriteLi ne("First query...")
dbDataReader = dbCommand.Execu teReader()
Do While dbDataReader.Re ad()
Console.WriteLi ne(dbDataReader (0))
Loop
dbDataReader.Cl ose()

Console.WriteLi ne("Change the database table contents using
an external tool, then press return.")
Console.ReadKey ()

Console.WriteLi ne("Second query...")
dbDataReader = dbCommand.Execu teReader()
Do While dbDataReader.Re ad()
Console.WriteLi ne(dbDataReader (0))
Loop
dbDataReader.Cl ose()

Console.WriteLi ne("Expecting the two queries to give the
same results, despite the external modification.")
Console.WriteLi ne("Press return to finish.")
Console.ReadKey ()

dbConnection.Cl ose()

Catch ex As Exception
Console.WriteLi ne(ex.Message)
End Try

End Sub

End Module

Hopefully the prompts make it clear how I have been testing this. When
I test it here, the change I make with an external tool when prompted
is shown in the second query: so it seems to me that the SET
TRANSACTION READ ONLY has had no effect.

Any more help appreciated.

Ashley.

Jun 20 '06 #3
Hi, ashley

as first suggestion, irrelevant to your problem, I would move some
clean up in a finally block to avoid leaving it open in case of
exceptions

Catch ex As Exception
Console.WriteLi ne(ex.Message)
Finally

If Not dbDataReader Is Nothing Then dbDataReader.Cl ose()
dbConnection.Cl ose()

End Try

back to the problem I do not have here Oracle. I will make some
hypotheses to be tested.

Is it possible that the external tool does a COMMIT which resets the
SET TRANSACTION READ ... ?

You could test if that is the case doing some change to the table
programmaticall y.

Let me know if this takes somewhere....

-tom

PS
I also have a curiosity: have you measured any performance improvement
by using an
OracleConnectio n instead of an OleDbConnection ?
as*********@gma il.com ha scritto:
to************* *@uniroma1.it wrote:
have you made sure you send the 5 commands in sequence - without closing
the connection - between a command and the following one?


Hi tom...

Thanks for the reply. I don't think I've closed the connection. Here
is the complete code (this is a Console application, by the way):

Imports System.Data.Ora cleClient ' for this to work, need to have
System.Data.Ora cleClient listed as a reference in the project
properties...

Module Module1

Sub Main()

Dim dbConnectionStr ing As String = "Password=ASHLE Y;User
ID=ASHLEY;Data Source=HAGRID"
Dim queryString As String = "SELECT * FROM TEST"

Dim dbConnection As OracleConnectio n
Dim dbCommand As OracleCommand
Dim dbDataReader As OracleDataReade r

Try
dbConnection = New OracleConnectio n(dbConnectionS tring)
dbConnection.Op en()

dbCommand = dbConnection.Cr eateCommand()
dbCommand.Comma ndText = "SET TRANSACTION READ ONLY NAME
'PDI_HSD'"
dbCommand.Execu teNonQuery()

dbCommand.Comma ndText = queryString

Console.WriteLi ne("First query...")
dbDataReader = dbCommand.Execu teReader()
Do While dbDataReader.Re ad()
Console.WriteLi ne(dbDataReader (0))
Loop
dbDataReader.Cl ose()

Console.WriteLi ne("Change the database table contents using
an external tool, then press return.")
Console.ReadKey ()

Console.WriteLi ne("Second query...")
dbDataReader = dbCommand.Execu teReader()
Do While dbDataReader.Re ad()
Console.WriteLi ne(dbDataReader (0))
Loop
dbDataReader.Cl ose()

Console.WriteLi ne("Expecting the two queries to give the
same results, despite the external modification.")
Console.WriteLi ne("Press return to finish.")
Console.ReadKey ()

dbConnection.Cl ose()

Catch ex As Exception
Console.WriteLi ne(ex.Message)
End Try

End Sub

End Module

Hopefully the prompts make it clear how I have been testing this. When
I test it here, the change I make with an external tool when prompted
is shown in the second query: so it seems to me that the SET
TRANSACTION READ ONLY has had no effect.

Any more help appreciated.

Ashley.


Jun 20 '06 #4
Hi tom -- thanks for the reply.

to************* *@uniroma1.it wrote:
as first suggestion, irrelevant to your problem, I would move some
clean up in a finally block to avoid leaving it open in case of
exceptions
Yes, a good idea -- thanks.
back to the problem I do not have here Oracle. I will make some
hypotheses to be tested.

Is it possible that the external tool does a COMMIT which resets the
SET TRANSACTION READ ... ?
Yes, the external tool does do a COMMIT. But that shouldn't reset the
SET TRANSACTION READ ONLY. When I test manually (substituting an
sqlplus session for the VB program), any changes I make in the external
tool don't show up in the sqlplus session after the SET TRANSACTION,
COMMIT or not.
I also have a curiosity: have you measured any performance improvement
by using an
OracleConnectio n instead of an OleDbConnection ?


I haven't tried OleDbConnection yet.

Ashley.

Jun 21 '06 #5
Ok. So let's try to determine who is responsible for the Reset of SET
TRANSACTION READ ... (perhaps ExecuteReader does it) let's put the
execute reader and close in a position where they cannot reset
and see if anything changes:

dbConnection.Op en()

dbDataReader1 = dbCommand1.Exec uteReader()
dbDataReader2 = dbCommand2.Exec uteReader()

"SET TRANSACTION READ ONLY NAME " here

Do While dbDataReader1.R ead()
Console.WriteLi ne(dbDataReader (0))
Loop

'manual changes here

Do While dbDataReader2.R ead()
Console.WriteLi ne(dbDataReader (0))
Loop
'test if equal

dbDataReader1.C lose()
dbDataReader2.C lose()

dbConnection.Cl ose()

Once you have determined which is the resetting instruction you con
possibly adjust statements in a better way.

Let me know...

-tom

as*********@gma il.com ha scritto:
Hi tom -- thanks for the reply.

to************* *@uniroma1.it wrote:
as first suggestion, irrelevant to your problem, I would move some
clean up in a finally block to avoid leaving it open in case of
exceptions


Yes, a good idea -- thanks.
back to the problem I do not have here Oracle. I will make some
hypotheses to be tested.

Is it possible that the external tool does a COMMIT which resets the
SET TRANSACTION READ ... ?


Yes, the external tool does do a COMMIT. But that shouldn't reset the
SET TRANSACTION READ ONLY. When I test manually (substituting an
sqlplus session for the VB program), any changes I make in the external
tool don't show up in the sqlplus session after the SET TRANSACTION,
COMMIT or not.
I also have a curiosity: have you measured any performance improvement
by using an
OracleConnectio n instead of an OleDbConnection ?


I haven't tried OleDbConnection yet.

Ashley.


Jun 22 '06 #6

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

Similar topics

4
40242
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 user commits. But in Informix there is this thing called ISOLATION LEVELS. For example by setting the ISOLATION LEVEL to DIRTY READ, a user will read dirty data, i.e. the last uncommited updated value of a field by some other user. Is
11
12690
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 read the new date. So process B starts "select ..." but does not get the previously inserted row. The timespan between commit and select is very short. (NOTE: two different sessions are used) Questions: 1.) Does commit when returning from call...
1
8207
by: Eirik Tryggeseth | last post by:
During deployment of an application using distributed transactions managed under COM+ on an Oracle 9i RAC database, we encounter situations where the load balancing mechanisms in the RAC result in that the component context in the distributed transaction (in our case two different COM components) cannot hold onto the same ODBC connection. Or it may be that the database session is changed dynamically for the ODBC connection, so that...
133
8970
by: jonathan | last post by:
hey all, I realize that this question might pop up from time to time, but I haven't seen it a while and things might of changed, so - Right now (July 2004) how does mysql stand up in comparison to oracle? We are seriously considering migrating our multi-processor oracle system to mysql to save on licensing costs, and would need several features that mysql may or may not have:
1
4184
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 the transaction and run it against an object it might fail. If I rerun the same transaction again it might work. But on trying again it might fail. If I disable transactions <Transaction(TransactionOption.Disabled)> the app runs and all the data...
4
3976
by: Abram Friesen | last post by:
Hi, I'm a developer for a software application vendor, and our application makes use of a customer-maintained Oracle 8i/9i database. We've had a customer request to support DB2 database, and I'm looking into the feasibility of migration. Our application runs on NT Server and, the DB2 database would be in some cases on a separate AIX machine, in other cases on an AS/400. There are two problems we are running into, both relating to our...
3
7111
by: OUSoonerTaz | last post by:
We are randomly getting this error message on our development and staging machines: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.; at System.Data.Common.UnsafeNativeMethods.OraMTSJoinTxn(OciEnlistContext pCtxt, IDtcTransaction pTrans) at System.Data.OracleClient.TracedNativeMethods.OraMTSJoinTxn(OciEnlistContext pCtxt, IDtcTransaction pTrans)
2
14221
by: Vinod Sadanandan | last post by:
All, Below listed are the new features in Oracle 11g ,please join me in this discussion to generate a testcase and analyze each of the listed features . Precompilers: Additional Array INSERT and SELECT Syntax Support by Pro*C/C++ and Pro*COBOL Precompilers: Dynamic SQL Statement Caching in Pro*C/C++ and Pro*COBOL Precompilers: Fix Execution Plan in Pro*C/C++ and Pro*COBOL Precompilers: Flexible B Area Length...
0
7987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8392
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8050
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8264
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6718
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.