Wednesday, April 05, 2006

Thank God for the newsgroups of 1997 and Google

A colleague who has since moved on to a new engagement emailed me about a vexing problem with some code which has been working for years and just started to error out. It is VB code retrieving results from Oracle and the error being returned was ORA-01422 Fetch too many rows. Don’t jump to conclusions, this isn’t an INTO statement -- we aren’t looking for just one row.

If mbIsADO Then
'ADO connection
Set oADORSet = moConnection.OpenResultSet(sSql)

I have to assume the comments and the variable names have meaning don’t I? Not so fast. When I look up the object model for ADO, I don’t see an OpenResultSet method of the ADO Connection object. Hmm… Clearly the code says if I’ve set some module level Boolean flag IsADO to TRUE, I expect that what I am using are ADO Objects. Right? Ah, but RDO has that method on it’s connection object. Googling RDO on this topic is more fruitful.

Part way through the back and forth, this friend mentioned that the query worked in SQL*Plus and it returned 122 rows which was the right answer. This got me thinking.

1. The company is growing so this query probably also has grown to fetch more records than it used to
and thus…
2. passed some threshold which is now causing the error.


I found this thread, which says that RDO [queries] have a MaxRows property and the default is 100 rows.

I suggested that they add a single line

oADORSet.MaxRows = 0

They should be fine. I’m going out on a limb publishing this before I know if this is correct. We shall see.

Other references are here and here.

No comments: