473,795 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Win32 Com + ADO: How to compare the result of a recordset to 'nothing'

Hi,
When using win32com.client , how do you test for a 'nothing' com object as you can in VB? I have an example here when using ADO to loop over multiple recordsets returned from a query. I get the following error:

Traceback (most recent call last):
File "C:\dev\python\ MySamples\dbtes t.py", line 14, in ?
rs.MoveFirst()
File "C:\Python23\li b\site-packages\win32c om\client\dynam ic.py", line 460, in __getattr__
raise AttributeError, "%s.%s" % (self._username _, attr)
AttributeError: <unknown>.MoveF irst

I'm assuming that after the result of rs.NextRecordSe t is invalid somehow (it shouldn't be, BTW, as a similar loop runs fine in VB).

In Perl, I'd just use : if (defined($rs).. ..

Any help appreciated,

Felix.

The code is as follows:
############### ############3
import win32com.client
conn = win32com.client .Dispatch("ADOD B.Connection")
conn.Connection String = "Driver={SQ L Server};Server= (local);Databas e=Test;Trusted_ Connection=yes; "
conn.Open()
rs = conn.Execute("T estSPXML")[0]
xmlString = ""
while rs != None:
rs.MoveFirst() # FAILS HERE ON THE SECOND ITERATION OF THE LOOP
while not rs.EOF:
xmlString = xmlString + rs.Fields[0].Value
rs.MoveNext()
rs = rs.NextRecordSe t()
print xmlString
conn.Close()
Jul 18 '05 #1
6 4268
At 07:53 AM 9/15/2003, Felix McAllister wrote:
[snip]
The code is as follows:
############## #############3
import win32com.client
conn = win32com.client .Dispatch("ADOD B.Connection")
conn.Connectio nString = "Driver={SQ L
Server};Server =(local);Databa se=Test;Trusted _Connection=yes ;"
conn.Open()
rs = conn.Execute("T estSPXML")[0]
xmlString = ""
while rs != None:
rs.MoveFirst() # FAILS HERE ON THE SECOND ITERATION OF THE LOOP
while not rs.EOF:
xmlString = xmlString + rs.Fields[0].Value
rs.MoveNext()
rs = rs.NextRecordSe t()
print xmlString
conn.Close()


I am learning how to use ADODB with SQL Server, so your example is very
timely. I know that I have to change the ConnectionStrin g, as I get this
error when running your example: "'Microsoft OLE DB Provider for ODBC
Drivers', '[Microsoft][ODBC SQL Server Driver][Shared Memory]SQL Server
does not exist or access denied.'"

What do I have to change?

Bob Gailer
bg*****@alum.rp i.edu
303 442 2625
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003

Jul 18 '05 #2
Bob,
You need to change the (local) part of the connection string to a SQL Server instance on your machine or network. You might also have to change the Trusted Connection=yes part to use a SQL Server login name and password, if that instance isn't set up for trusted connections.
Felix.
Jul 18 '05 #3
"Felix McAllister" <fe************ **@hotmail.com> wrote in message news:<tv******* ************@ne ws.indigo.ie>.. .
Hi,
When using win32com.client , how do you test for a 'nothing' com object as you can in VB? I have an example here when using ADO to loop over multiple recordsets returned from a query. I get the following error:

Traceback (most recent call last):
File "C:\dev\python\ MySamples\dbtes t.py", line 14, in ?
rs.MoveFirst()
File "C:\Python23\li b\site-packages\win32c om\client\dynam ic.py", line 460, in __getattr__
raise AttributeError, "%s.%s" % (self._username _, attr)
AttributeError: <unknown>.MoveF irst

I'm assuming that after the result of rs.NextRecordSe t is invalid somehow (it shouldn't be, BTW, as a similar loop runs fine in VB).

In Perl, I'd just use : if (defined($rs).. ..

Any help appreciated,

Felix.

The code is as follows:
############### ############3
import win32com.client
conn = win32com.client .Dispatch("ADOD B.Connection")
conn.Connection String = "Driver={SQ L Server};Server= (local);Databas e=Test;Trusted_ Connection=yes; "
conn.Open()
rs = conn.Execute("T estSPXML")[0]
xmlString = ""
while rs != None:
rs.MoveFirst() # FAILS HERE ON THE SECOND ITERATION OF THE LOOP
while not rs.EOF:
xmlString = xmlString + rs.Fields[0].Value
rs.MoveNext()
rs = rs.NextRecordSe t()
print xmlString
conn.Close()


Recordsets have a .BOF property that is similar to .EOF, but indicates
that your cursor is before the first record. If both .BOF and .EOF
are true, you have a null recordset. So something like:

if not(rst.BOF and rst.EOF):
rst.MoveFirst()

should work.
Jul 18 '05 #4
logistix at cathoderaymissi on.net wrote:
Recordsets have a .BOF property that is similar to .EOF, but indicates
that your cursor is before the first record. If both .BOF and .EOF
are true, you have a null recordset. So something like:

if not(rst.BOF and rst.EOF):
rst.MoveFirst()

should work.


Maybe should, but frequently doesn't. Although the books tell you to do
this, I've never found it to be any use. SQL Server, at any rate,
always sets the cursor to the first record, so rst.EOF is enough to test
for no records. The problem comes when nothing is returned, which is
different to no records being returned. (In Query Analyser, you see
nothing, instead of column names with nothing underneath.) In that
case, I find checking for rst.State==1 does the trick. I think BOF
fails the same way as EOF in this case (if the record set's closed, it's
an error to even ask where the cursor is).

From the error message, I don't think this is the OP's problem, though.
You would see something telling you not to do that on a closed record
set. I suggest poking the object in an interpreter, and looking in
pywintypes, if nobody has any better ideas.
Graham

Jul 18 '05 #5
"Felix McAllister" <fe************ **@hotmail.com> wrote in message news:<tv******* ************@ne ws.indigo.ie>.. .
Hi,
When using win32com.client , how do you test for a 'nothing' com object as you can in VB? I have an example here when using ADO to loop over multiple recordsets returned from a query. I get the following error:

Traceback (most recent call last):
File "C:\dev\python\ MySamples\dbtes t.py", line 14, in ?
rs.MoveFirst()
File "C:\Python23\li b\site-packages\win32c om\client\dynam ic.py", line 460, in __getattr__
raise AttributeError, "%s.%s" % (self._username _, attr)
AttributeError: <unknown>.MoveF irst

I'm assuming that after the result of rs.NextRecordSe t is invalid somehow (it shouldn't be, BTW, as a similar loop runs fine in VB).

In Perl, I'd just use : if (defined($rs).. ..

Any help appreciated,

This is just a guess, but is it anything to do with NextRecordset
returning a tuple (recordset, records affected)?

(Don't think that should end up being wrapped in a
win32com.client .dynamic
wrapper though?)

You could try putting some print statements into
win32com.client .dynamic
to see exactly what you're getting back.

Good luck,
Giles Brown
Jul 18 '05 #6
Thanks to all who replied to my posting.

There were a number of things wrong with my code.

1. Giles Brown was correct in stating that the NextRecordset method returns a tuple. I should have seen this in the debugger when I printed the value out:
[Dbg]>>> rs.NextRecordse t()
(<COMObject NextRecordset>, -1)

2. There was a typo in the call to NextRecordset - I had "NextRecord Set" [capital S]. I didn't know that case mattered.

The correct loop code is as follows:
while rs != None:
rs.MoveFirst()
while not rs.EOF:
xmlString = xmlString + rs.Fields[0].Value
rs.MoveNext()
rs = rs.NextRecordse t()[0]
Felix.
Hi,
When using win32com.client , how do you test for a 'nothing' com object as you can in VB? I have an example here when using ADO to loop over multiple recordsets returned from a query. I get the following error:

Traceback (most recent call last):
File "C:\dev\python\ MySamples\dbtes t.py", line 14, in ?
rs.MoveFirst()
File "C:\Python23\li b\site-packages\win32c om\client\dynam ic.py", line 460, in __getattr__
raise AttributeError, "%s.%s" % (self._username _, attr)
AttributeError: <unknown>.MoveF irst

I'm assuming that after the result of rs.NextRecordSe t is invalid somehow (it shouldn't be, BTW, as a similar loop runs fine in VB).

In Perl, I'd just use : if (defined($rs).. ..

Any help appreciated,

Felix.

The code is as follows:
############### ############3
import win32com.client
conn = win32com.client .Dispatch("ADOD B.Connection")
conn.Connection String = "Driver={SQ L Server};Server= (local);Databas e=Test;Trusted_ Connection=yes; "
conn.Open()
rs = conn.Execute("T estSPXML")[0]
xmlString = ""
while rs != None:
rs.MoveFirst() # FAILS HERE ON THE SECOND ITERATION OF THE LOOP
while not rs.EOF:
xmlString = xmlString + rs.Fields[0].Value
rs.MoveNext()
rs = rs.NextRecordSe t()
print xmlString
conn.Close()

Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4808
by: Mac Davis | last post by:
Is it possible to use ADO in global.asa? I simply want to creat a log of each visit to the site? Thanks, -dmd-
3
23744
by: Zlatko Matiæ | last post by:
Hello. I know how to call a parameterized stored procedure by using ADODB command object and parameters, but how can I execute the same query using adCmdText instead of adCmdStoredProc? Namely I created the CommandText string with declare statement for parameters before the select statement. No error is displayed, but also, no records are shown iether. It seems that the server can't recognize parameters. The select statement is exactly...
0
7719
by: gm | last post by:
Immediately after generating the Access application from the Source Safe project I get: "-2147467259 Could not use ''; file already in use." If Access database closed and then reopened I get: "-2147467259 The database has been place in a state by user 'Admin' on machine ..... that prevents it from being opened or locked."
5
2157
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/adonetprogmsdn.asp The Design of ADO To better understand the model and design of ADO.NET, it is helpful to review some of the core aspects of ADO. ADO uses a single object, the Recordset, as a common representation for working with all types of data. The Recordset is used for working with a forward-only stream of results from a database, for scrolling...
9
6683
by: Matthew Wells | last post by:
Hello, I have a main form with two continuous subforms - neither is using master/child fields. Subform2 is bound to a local temp table. When I update a record on subform1 it executes a function on subform2 that deletes the records from teh temp table and repopulates it and of course executes a me.requery afterweards. This is done with an ado connection object. The problem is that subform2 doesn't "see" the data for a few seconds. ...
4
8992
by: ashleycvernon | last post by:
I am using MS Access forms as a front end to a backend SQL Server Database. I am trying to use an ADO connection to return a Select Statement from the SQL Server to an Access form to be viewable by the user. I have been able to establish the connection to the SQL Server and have verified that the SQL statement is correct. I am completely new to ADO and I can't figure out how to display the data returned in the ADO recordset. Could...
7
8445
by: iheartvba | last post by:
Hi, I am trying to figure out how to write queries using ADO For example if I want to Select (Field) From (Table) Where (Field) = (TextBox in Form) and just open that query as a recordset. I am getting the following error: RunTime error 3709 The Connection Cannot be used to perform this operation. It is either closed or invalid in this context. This is my code:
6
4872
by: Greg Strong | last post by:
Hello All, Is is possible to use an ADO recordset to populate an unbound continuous Subform? I've done some Googling without much luck, so this maybe impossible, but let me try to explain why. I've been exploring using Access as a front end to both SQL MSDE and Oracle XE. I'm in the process of writing a class to handle the basics of the ADO connection and recordsets. The basic relationships are as follows:
0
9012
ADezii
by: ADezii | last post by:
When you create an ADO Recordset, you should have some idea as to what functionality the Recordset does/does not provide. Some critical questions may, and should, be: Can I add New Records to the Recordset? Does the Recordset support Bookmarks? Can we use the Find and/or Seek Methods with this Recordset? Does the Recordset support the use of Indexes? Will the Absoluteposition property be able to be used on this Recordset? etc....
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.