Solved

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

Posted on 2009-07-09
1
1,000 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
ID: 24817197
Solution found, just need to change Recordset.CursorLocation properly.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
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.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

791 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