472,348 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.Open()
dbCommand = dbConnection.CreateCommand()
dbCommand.CommandText = "SET TRANSACTION READ ONLY"
dbCommand.ExecuteNonQuery()

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.Open()
dbTransaction = dbConnection.BeginTransaction(IsolationLevel.Snaps hot)
dbCommand.Transaction = 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.OracleClient :(

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+mysql and some experience in VB6.

Any help much appreciated.

Ashley.

Jun 19 '06 #1
5 7423
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*********@gmail.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.Open()
dbCommand = dbConnection.CreateCommand()
dbCommand.CommandText = "SET TRANSACTION READ ONLY"
dbCommand.ExecuteNonQuery()

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.Open()
dbTransaction = dbConnection.BeginTransaction(IsolationLevel.Snaps hot)
dbCommand.Transaction = 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.OracleClient :(

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+mysql 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.OracleClient ' for this to work, need to have
System.Data.OracleClient listed as a reference in the project
properties...

Module Module1

Sub Main()

Dim dbConnectionString As String = "Password=ASHLEY;User
ID=ASHLEY;Data Source=HAGRID"
Dim queryString As String = "SELECT * FROM TEST"

Dim dbConnection As OracleConnection
Dim dbCommand As OracleCommand
Dim dbDataReader As OracleDataReader

Try
dbConnection = New OracleConnection(dbConnectionString)
dbConnection.Open()

dbCommand = dbConnection.CreateCommand()
dbCommand.CommandText = "SET TRANSACTION READ ONLY NAME
'PDI_HSD'"
dbCommand.ExecuteNonQuery()

dbCommand.CommandText = queryString

Console.WriteLine("First query...")
dbDataReader = dbCommand.ExecuteReader()
Do While dbDataReader.Read()
Console.WriteLine(dbDataReader(0))
Loop
dbDataReader.Close()

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

Console.WriteLine("Second query...")
dbDataReader = dbCommand.ExecuteReader()
Do While dbDataReader.Read()
Console.WriteLine(dbDataReader(0))
Loop
dbDataReader.Close()

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

dbConnection.Close()

Catch ex As Exception
Console.WriteLine(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.WriteLine(ex.Message)
Finally

If Not dbDataReader Is Nothing Then dbDataReader.Close()
dbConnection.Close()

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
programmatically.

Let me know if this takes somewhere....

-tom

PS
I also have a curiosity: have you measured any performance improvement
by using an
OracleConnection instead of an OleDbConnection ?
as*********@gmail.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.OracleClient ' for this to work, need to have
System.Data.OracleClient listed as a reference in the project
properties...

Module Module1

Sub Main()

Dim dbConnectionString As String = "Password=ASHLEY;User
ID=ASHLEY;Data Source=HAGRID"
Dim queryString As String = "SELECT * FROM TEST"

Dim dbConnection As OracleConnection
Dim dbCommand As OracleCommand
Dim dbDataReader As OracleDataReader

Try
dbConnection = New OracleConnection(dbConnectionString)
dbConnection.Open()

dbCommand = dbConnection.CreateCommand()
dbCommand.CommandText = "SET TRANSACTION READ ONLY NAME
'PDI_HSD'"
dbCommand.ExecuteNonQuery()

dbCommand.CommandText = queryString

Console.WriteLine("First query...")
dbDataReader = dbCommand.ExecuteReader()
Do While dbDataReader.Read()
Console.WriteLine(dbDataReader(0))
Loop
dbDataReader.Close()

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

Console.WriteLine("Second query...")
dbDataReader = dbCommand.ExecuteReader()
Do While dbDataReader.Read()
Console.WriteLine(dbDataReader(0))
Loop
dbDataReader.Close()

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

dbConnection.Close()

Catch ex As Exception
Console.WriteLine(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
OracleConnection 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.Open()

dbDataReader1 = dbCommand1.ExecuteReader()
dbDataReader2 = dbCommand2.ExecuteReader()

"SET TRANSACTION READ ONLY NAME " here

Do While dbDataReader1.Read()
Console.WriteLine(dbDataReader(0))
Loop

'manual changes here

Do While dbDataReader2.Read()
Console.WriteLine(dbDataReader(0))
Loop
'test if equal

dbDataReader1.Close()
dbDataReader2.Close()

dbConnection.Close()

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

Let me know...

-tom

as*********@gmail.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
OracleConnection 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
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...
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...
1
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...
133
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...
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...
4
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...
3
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...
2
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...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.