Solved

Possible to use ADODB Recordset.AddNew function to add new record to database?

Posted on 2009-07-09
1
985 Views
Last Modified: 2013-11-18
Hi Experts:

     I tried to use the following test code to insert records to a database table.
******************************************************************************
con = win32com.client.Dispatch(r'ADODB.Connection')
con.Open("<this is a connection string>")
con.Execute("<dbms_session.set_role command>")
cDataset = win32com.client.Dispatch(r'ADODB.Recordset')
cDataset.Open("SELECT * FROM table_name WHERE 1=0", con, 3, 3, 1)
cDataset.AddNew()
cDataset.Fields.Item("AREA").Value = 1
cDataset.Update()
*************************************************************************************

How ever I got the following error message
*************************************************************************************
  File "<COMObject ADODB.Recordset>", line 3, in AddNew
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'ADODB.Recordset'
, 'Current Recordset does not support updating. This may be a limitation of the
provider, or of the selected locktype.', 'C:\\WINDOWS\\HELP\\ADO270.CHM', 124064
8, -2146825037), None)
*************************************************************************************

I check the spec of the AddNew function at
http://msdn.microsoft.com/en-us/library/ms675544(VS.85).aspx
but could not find the reason.

The values of the last three parameters of Recordset.Open (cursor type, lock type, options) are from a piece of VB code, so I cannot believe they are wrong. I also tried to chaned them around, but still not working.

The ADODB.Connection object should also be correct, because on another version of Python code I used con.Execute("<insert statement>") to insert some record instead of Recordset.AddNew, and it worked.

The python code is following the tutorial http://www.ecp.cc/pyado.html

How can I make it work? Thank you!

Background information: I was originally using con.Execute("<insert statement>")  to process millions of database records, but it was slow, so I want to see whether there is faster alternatives. If there is the third way (faster way) to insert records to a database with password protected role using Python and PythonWinExtension, please let me know... and then I do not need to use ADODB.
0
Comment
Question by:huangs3
1 Comment
 

Accepted Solution

by:
huangs3 earned 0 total points
Comment Utility
Solution found, just need to change Recordset.CursorLocation properly.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database

743 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

11 Experts available now in Live!

Get 1:1 Help Now