?
Solved

Need to do a COMMIT after a SELECT (VB)

Posted on 2007-12-03
6
Medium Priority
?
591 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 66

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 66

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

864 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