Solved

Need to do a COMMIT after a SELECT (VB)

Posted on 2007-12-03
6
572 Views
Last Modified: 2008-02-01
I am running a simple SELECT statement in VB using ADODB something like this:
Dim DBCmd as New ADODB.Command
<etc>
DBCmd.Execute "SELECT * FROM USER_DATA WHERE PERSON_ID  = '" & PersonID & "'"
Set PersonRS = DBCmd.Execute

This query works fine.  I am told that the data is actually housed in another Oracle database instance, and I need to do a "COMMIT" after the select.  How do I do this?

0
Comment
Question by:UPRRDevelopers
6 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 20399277
Not sure about the Oracle part, but .Execute is usually only for action queries (INSERT, UPDATE, DELETE, INSERT INTO), and not for a SELECT query.

If your query does not use parameters, give this a whirl

PersonRs.Open "SELECT * FROM USER_DATA WHERE PERSON_ID  = '" & PersonID & "'", cnYourConnectionObject
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 20399285
also, COMMIT is used in transactions, as in BEGIN TRAN, COMMIT TRAN, ROLLBACK TRAN.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 20399785
In addition to jimhorn's last message, a COMMIT is only necessary when you have used SQL to affect a change (UPDATE, INSERT or DELETE) in the underlying table.  You do not need a Transaction when all you are doing is retrieving data (SELECT...) from the database.

AW
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20401979
its good to use commit only if you do any changes in the records in the database. since select statement reads only the records, there is no use of using commit statement. commit transaction can be used only if you insert or update records. if you use commit statement in select there is no use of using it. it does nothing.
0
 

Author Comment

by:UPRRDevelopers
ID: 20403384
I know about doing a commit after an alteration, and this was a surprise to me as well.  But here's the deal.  I am doing a query on a View in Database A.  The data is actually housed in Database B.  I am told that when I do the query on the view in Database A, it is taking rollback space in Database A as it does the "cross-select".  This is gradually increasing as the queries continue, and if my users do not exit the app (or lose connection to the network before the rollback space is released) then eventually, the rollback space fills, and my other apps fail due to the lack of rollback space available.  I am told that the fix for this is to perform a commit after the select, which will apparently release the rollback space from that query immediately.  My problem is that I have no idea how to do a Commit after a Select.  Hope that makes sense.
0
 
LVL 10

Accepted Solution

by:
3_S earned 500 total points
ID: 20404804
In your last post you are close to the solution uprrDevelopers
It's not because you implicitly start a transaction that the database doesn't start one for you. (even for a select)
So every time you do a select (or whatever) the database starts a transaction for you. (even if you do not ask).  This takes up resources and you should release these as soon as possible.  So it its still best to start a transaction your own so you have control over it.  (else it's possible it stays open as long as your application is running.) Or in event of a crash of your program it could stay open as long as the database is running.

DBCmd.ActiveConnection.BeginTrans()
....
DBCmd.ActiveConnection.CommitTrans()
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now