Solved

Need to do a COMMIT after a SELECT (VB)

Posted on 2007-12-03
6
576 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

856 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