Update disconnected ADO recordset ID field with new ID - vb6

Updating an old VB6 app using ADO and disconnected recordsets. Works just fine except there are some old ADODC objects I'm also updating to use disconnected recordsets. I've written code to insert new records and return the new ID value which is great.
However, when I try to update the current new record (in the recordset via .AddNew), I get "Multiple-step operation generated errors. Check each status value."
I can update other columns just fine. Just not the SQL identity column in the recordset. All I want is for subsequent references to that column to now have the correct information.
The searches on that error seem to indicate that it's possible to update the value, but I've tried CVar(newID), just newID and nothing seems to work.
The Recordset is set as
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
I could hack each instance to somehow reload the entire recordset with the new object, but that seems like a lot of workaround. In most cases, the newid never gets used until it's reloaded. But I'm trying to replicate the action of a connected ADODC which would save the record and refresh itself with the new id.
Any options?

Related

Cannot update Oracle view from JDBC

Overview: Need to read row from Oracle view and create a Notes document, save document, then write Document Unique ID back to Oracle.
I am able to read connect and read data no problem. I am using a type 4 connection connecting to an Oracle 11 database. The Oracle view is setup to allow Updating. The view has nothing in it that is outline here: In Oracle, is it possible to INSERT or UPDATE a record through a view?
*With the same username and password, you are able to successfully update view by typing in SQL statement.
*Tried using conn.setAutoCommit(false); This had no effect.
*Verified that the result set was updatable (1008)
*User has been given full DBA access (temporarily)
*I have tried every possible combination of the first parameter in the createStatement method
...
Statement statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = statement.executeQuery(fetch);
...
String UNID = doc.getUniversalID(); //gets unique id from saved Notes Document
System.out.println("This is what to write to Oracle:" + UNID);
System.out.println("is updatable=1008, not updatable=1007 value is:" + rs.getConcurrency());
System.out.println("is Result Set Closed:" + rs.isClosed());
rs.updateString("NOTES_DOC_ID", UNID);
System.out.println("got past updating NOTES_DOC_ID column");
rs.updateRow(); //fails here
Here is the error from console:
This is what to write to Oracle:BF8091259610C61B87257B16005C14FB
is updatable=1008, not updatable=1007 value is:1008
is Result Set Closed:false
got past updating NOTES_DOC_ID column
java.security.AccessControlException: Access denied (java.lang.RuntimePermission exitVM.0)
Prior to asking for the user to have DBA access I would get a
java.sql.SQLSyntaxErrorException: ORA-01031: insufficient privileges
I think this a big clue. My DBA doesn't know what further access to give me.
The DBA is wanting me to start using ref cursors, which is fine, but I suspect there is some kind of security setting for JDBC access that is tripping me up, and I want to explore that first. If there is a security issue, then I don't think changing the way I read the rows is going to make a difference. Most of all the documentation on how to do this was obtained from Oracle's website, as well as this site.
I am going to answer my question and explain how I got past this roadblock. In the end, I basically did what 'a_horse_with_no_name' suggested.
Instead of using the resultSet cursor or a ref cursor to perform the update, I was able to use a plain UPDATE statement. This was possible, because I was able to convince the DBA to create a column for a unique identifier. We could never get around the exceptions caused by the updateRow() method of the resultSet. Prior to him adding the unique identifier, there was not a key in which to reliably use the UPDATE statement.
Here is the code where updateSQL is a string holding the update SQL statement:
updateResultInt = updateStatement.executeUpdate(updateSQL);
It returns a 1 if successful.
One word of caution, if you are using a tools like TOra or sql plus to check your update statements, you have to remember to manually commit them. If you don't your java agent will hang when trying to run it. Here is an good reference that helped me with that issue: SQL Update hangs Java program
Thanks to those who commented!

vb6 oracle9i application, logical error-recordset remains empty

Currently I am working on a project that forces me to use Vb6 as a front end and Oracle 9i as a backend in my application. I need to retrieve data from a table in oracle, and display it in a VB6 form. Im using a recordset for this, but for some reason it doesnt contain any record even when a valid record is present in the table in question. Can anyone tell me what's wrong? Any help would be appreciated. My code is as follows-
Private Sub Command1_Click()
Dim sql As String
Set rs = New ADODB.Recordset
sql = "select test23.phoname from test23 where test23.ops='" + Text1.Text + "'"
rs.Open sql, con, adOpenStatic, adLockOptimistic
If rs.EOF = False Then
Form7.Show
Form7.Label2.Caption = rs.Fields("phoname")
End If
End Sub
The if statements never execute, as the recordset always seems empty. If I remove the EOF condition I get a runtime error 3021. Is there something wrong with my sql query? The table test23 is already present in my oracle database with attributes serialno, phoname and ops.
Thanks-
Ron
I have struggled through this myself some years ago. The problem could be in several areas: specificaly the connection, the Oracle drivers, the Oracle home or the query itself.
I would strongly recommend that you download the free version of TOAD which will allow you to test both your connection (I assume ODBC of some sort) and you can then execute the query manually using TOAD.
Are you getting any exceptions?
Hopefully from this you can then correct your code/connection/query.
Good luck
I would also point out that adoOpenStatic and adoLockOptimistic are mutually exclusive property values, as optimistic locking only applies to updatable recordsets and static recordsets aren't updatable (except in batch mode with adoLockBatchOptimistic). This may be confusing the Oracle OLEDB provider somehow.

error in connection string in vb6.0

Dim rs As New ADODB.Recordset
strConnectionString = "Provider=SQLOLEDB.1;Integrated Security=True;Initial Catalog=Hospital_ABC;Data Source=ITEM-47791\SQLEXPRESS;Persyst Security Info=False;Command Properties='Command Time Out=45'"
Set connexion = New ADODB.Connection
connexion.ConnectionString = strConnectionString
connexion.ConnectionTimeout = 30
connexion.Open strConnectionString
rs.Open "insert into student_info(name,rollNo,age, class,address,assigned_teacher)values('name',rollno,age,'cls','add','assteac')", connexion
i am using this code to insert value inn my table ,,,but i got error as--run time error( multiple step OLEDB operation generated error, check each OLEDB status value, if available)
please check it what wrong in thos code .....
Look at this:
http://support.microsoft.com/kb/269495
It says:
The following are two possible causes
of this error:
In the registry, under the key for an OLE DB provider's CLSID, there may
be an entry named OLEDB_SERVICES. If
the OLE DB provider that is used to
make the ADO connection does not have
the OLEDB_SERVICES entry, and ADO
tries to set up a property that is not
supported by the provider, the error
occurs. For more information about
this registry entry, see the
"Resolution" section.
If OLEDB_SERVICES entry exists but there is a problem in the ADO
connection string, the error occurs.
Do not use this in connection string
Persyst Security Info=False;Command Properties='Command Time Out=45'
try this:
rs.Open "insert into student_info(name,rollNo,age,class,address,assigned_teacher) values('n',1,1,'c','a','a')", connexion
For me, the error usually happens when a data is too long for the field. You can further troubleshoot this by updating one field at a time to find the one that is broken (Update name, then update name and number, then name and number and age, etc).

assign table values to recordset and update with another recordset using vb6

I want to assign database table columns to recordset in vb6. And i want update them with the values that i have in my another recordset. Is that possible?
How to assign the data from table to recordset?
An ADODB recordset is not a mirror of a database table. The recordset contains whatever you want it to based on the query you provide it. So to load the data from the database into the recordset you need to execute a query. This can be done in two ways.
Use the ADODB.Connection.Execute method and set your recordset to the result.
Dim con as New ADODB.Connection
Dim rs as ADODB.Recordset
con.ConnectionString = "some connection string"
con.Open
Set rs = con.Execute("SELECT * FROM table")
Create an ADODB.Recordset object, specify the connection and then call the Open method passing it a query.
Dim con as New ADODB.Connection
Dim rs as New ADODB.Recordset
con.ConnectionString = "some connection string"
con.Open
Set rs.ActiveConnection = con
rs.Open "SELECT * FROM table"
The query can be as simple or complex as you want it be. The query could ask for fields from multiple tables and the recordset will still contain the results of the query, however you won't be able to tell which table the fields are from.
A fabricated ADODB Recordset object is a fine container object because it has some great methods built in: Filter, Sort, GetRows, GetString, Clone, etc plus support for paging, serializing as XML, etc. For details see "Adding Fields to a Recordset" in this MSDN article.
But if you are working with database data, why not just execute a query?

MS-Access ODBC Connection to Oracle for SQL

I'm trying to connect to an Oracle Database with Access 2003.
I want to use an ODBC connection and I want to set it up so that the user doesn't need to enter a password.
One of the problems I am having though is my sql query uses INTERFACE.Products and Access sees the period and thinks I'm trying to opening a file. IE Interface.MDB, when thats a part of my sql query.
Option Compare Database
Function OracleConnect() As Boolean
Dim ws As Workspace
Dim db As Database
Dim LConnect As String
Dim myQuery As String
Dim myRS As Recordset
On Error GoTo Err_Execute
LConnect = "ODBC;DSN=Oracle;UID=user;PWD=password;"
'Point to the current workspace
Set ws = DBEngine.Workspaces(0)
'Connect to Oracle
Set db = ws.OpenDatabase("", False, True, LConnect)
myQuery = "Select * from INTERFACE.Products"
Set rst = db.OpenRecordset(myQuery)
rst.Close
db.Close
Exit Function
Err_Execute:
MsgBox MsgBox("Error Number: " & Err.Number & " Message: " & Err.Description)
End Function
Could you try something like:
Set rst = db.OpenRecordset(mQuery, dbOpenSnapshot, dbSQLPassThrough)
This would just send the query verbatim to the Oracle database.
In the Access documentation for OpenRecordset you'll find this note:
If you open a Recordset in a Microsoft Access workspace and you don't specify a type, OpenRecordset creates a table-type Recordset.
This may be the source of the error you're getting.
As a rule, I would suggest to always be explicit in your parameters to OpenRecordset: the default behaviour isn't always consistent and it can generate strange errors.
I'm not sure about your design, but one way to make things a bit easier for you may be to simply create linked tables in Access.
In that case, you would be able to write queries against your INTERFACE.Products Oracle table as if if were a local Products table.
It would also save you from having to manage the connections yourself.
The recordset you are creating must use a query written with Access SQL. The table must be an Access table (a table defined in the mdb). It can be a local table or linked table. An Access table cannot have a "." (dot) in its name. If you were to link the Oracle table INTERFACE.Products in Access it would be INTERFACE_Products (Access will replace illegal characters in the remote database table name with "_") unless you renamed it in Access. Thus your query should be "Select * from INTERFACE_Products"
It is possible to create a recordset using Oracle SQL, but that must be created with a Pass-Through query.

Resources