Solved

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

Posted on 2009-07-09
1
1,022 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

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.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses

626 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