Problems with Tamino ItemIterator, throws System Null Refere

When I try to execute the QueryItemIterator sample which is provided in the QuerySamples of Tamino XML Server’s .NET API, I get an exception because of the ItemIterator.
The system throws an exception while executing the next() method of the ItemIterator.
The code is:

using System;

using System.Xml;
using System.Diagnostics;
using System.Collections;

using SoftwareAG.Tamino.Api;

namespace SoftwareAG.Tamino.QuerySamples
{
///


/// Demonstrates how to use the TaminoItemIterator class of the Tamino API to
/// iterate through a query result set. Each individual item in the list is accessed
/// as an XmlNode.
///

///
///
/// Usage: QueryItemIterator ‘Tamino URL’ ‘Collection’ ‘XQuery’ ‘PageSize’
///


/// Example: QueryItemIterator http://myserver/tamino/mydb APISimpleSamples input()/Property[@Category=‘Sell’] 5
///

///
/// If a nonzero pagesize is specified, the Tamino cursor is used. A Tamino cursor
/// cannot be used in mode TaminoConnectionMode.AutoCommit, therefore this example opens the
/// connection in mode TaminoConnectionMode.LocalTransaction.
///
///
public class QueryItemIterator
{

///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
// process args
if ( args.Length != 4 )
{
Console.WriteLine(“Usage: QueryItemIterator ‘Tamino URL’ ‘Collection’ ‘XQuery’ ‘PageSize’”);
Console.WriteLine(“Example: QueryItemIterator http://myserver/tamino/mydb APISimpleSamples input()/Property[@Category=‘Sell’] 5”);
return;
}

string dbUrl = args[0];
string collection = args[1];
string xquery = args[2];
int pageSize = int.Parse(args[3]);

Console.WriteLine("Tamino URL = “+dbUrl+”, Collection = "+collection+
", XQuery = “+xquery+”, PageSize = “+pageSize);

// create connection
TaminoConnection connection = new TaminoConnection(dbUrl);

// open connection
connection.Open(TaminoConnectionMode.LocalTransaction);

// begin transaction
TaminoTransaction tx = connection.BeginTransaction();

// create command for collection
TaminoCommand command = connection.CreateCommand(collection);

// do query
TaminoQuery query = new TaminoQuery(xquery);
TaminoQueryResponse qr = command.Query(query, pageSize);
Trace.Assert(qr.ReturnValue.Equals(“0”), qr.ErrorText);
TaminoItemIterator itemIt = qr.GetItemIterator();

while(itemIt.Next())
{
XmlNode node = itemIt.GetNode();
Console.WriteLine(“Item[”+itemIt.AbsoluteIndex+”]: "+node.OuterXml);
}
// close the query result set
qr.Close();

// close connection - this will commit the local transaction implicitly
connection.Close();
}
}
}


Stack Trace is like below:
C:\TAMINO\TAMINO~1\SAMPLES\QUERYS~1\QUERYI~1\BIN\DEBUG>QueryItemIterator http://
ServerName/tamino/Test TestCollection input()/Property[@Category=‘Sell’] 5
Tamino URL = http://ServerName/tamino/Test, Collection = TestCollection, XQuery = in
put()/Property[@Category=‘Sell’], PageSize = 5

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at SoftwareAG.Tamino.Api.Response.ResponseHandler2.GetCursor()
at SoftwareAG.Tamino.Api.TaminoPageIterator.ReadPage(Boolean next)
at SoftwareAG.Tamino.Api.TaminoPageIterator.Next()
at SoftwareAG.Tamino.Api.TaminoItemIterator.Next()
at SoftwareAG.Tamino.QuerySamples.QueryItemIterator.Main(String[] args) in c:
\tamino\taminoapi4dotnet\samples\querysamples\queryitemiterator\queryitemiterato
r.cs:line 71


I also wrote a similar code in an ASP.NET page with C#, and it throws the same exception. I am running Tamino XML Server 4.1.1.1 on a Windows 2000 Server and trying to execute the code on a windows 2000 pro machine where .NET Framework version 1.0 is installed…

I will be glad if someone can help me,
Thank you…

What response do you get if you enter the following request into a browser:

http://ServerName/tamino/Test/TestCollection?_xquery=in
put()/Property[@Category=‘Sell’]

This is a simple way of trying out commands using the HTTP interface.

thank you very much for your help, when I enter that in http address, it displays the property records correctly, so I guess the problem should be in the implementation of the next method of Iterator. the reference says it should return false if the iterator can’t move, so why does it throw that exception?? Besides it doesn’t throw the exception during the construction, I also added a reset() method, again it doesn’t throw an exception but it throws an exception when next() method is called…

This is the output I get when I wrote the query in the address bar:

<?xml version="1.0" encoding="ISO-8859-1" ?>
- <ino:response xmlns:ino=“http://namespaces.softwareag.com/tamino/response2” xmlns:xql=“http://metalab.unc.edu/xql/”>
- <xq:query xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>
- <![CDATA[ input()/Property[@Category='Sell']
]]>
</xq:query>
- <ino:message ino:returnvalue=“0”>
ino:messagelineXQuery Request processing</ino:messageline>
</ino:message>
- <xq:result xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>
-
-
NE
68045
Oakland
8245 Keys St

-
Hot Tub, Formal Dining Room, Guest Suite; Hardwood Floors; Lot Features: Fenced Yard
670
3
1

-
Ian Bannen
1-637-314-4634
Ian.Bannen@nasa.org

130500

-
-
NC
28531
Harkers Island
1435 Western Hutt Road

-
Great Room, Eat-in Kitchen; Hardwood Floors; Lot Features: Waterview; Vicinity: Golf in the neigbourhood
820
2
1

-
Michael Caine
1-313-884-7633
Michael.Caine@mail1.com

145000

-
-
TX
75212
Dallas
7156 Belford Court

-
Workshop, Study/Office, Balcony, Recreation Room; Hardwood Floors, Fireplace, Gas Heat; Lot Features: Boat Facilities, Lot with Trees, Tennis Court, Golf Course
1360
4
1

-
Robert Addie
1-791-254-3238
Robert.Addie@ne.emails.net

3093800

-
-
TX
75212
Dallas
3784 Driver Crescent

-
Hot Tub; Hardwood Floors, Gas Heat; Lot Features: Fenced Yard, Cul-de-sac Location; Vicinity: Golf in the neigbourhood
580
2
1

-
Anthony Andrews
1-341-227-7754
Anthony.Andrews@usermail.com

1290200

-
-
CA
94112
San Francisco
5991 Edelweiss Grove

-
Storage Area; Central Air; Lot Features: Tennis Court; Vicinity: Golf in the neigbourhood
610
3
1

-
Francesca Annis
1-103-800-4888
Francesca.Annis@world.compuserve.com

1413400

-
-
CA
94112
San Francisco
9695 Garth Lane

-
Laundry Room, Guest Suite; Hardwood Floors, Central Air, Fireplace, Gas Heat; Lot Area: 2729; Lot Features: Fenced Yard, Swimming Pool, Car Garage, Quiet Neighbourhood, Lot with Trees, Golf Course
1020
6
2

-
Rowan Atkinson
1-916-730-7460
Rowan.Atkinson@ail.showstar.com

2306200

-
-
TX
75212
Dallas
4207 Hardy St

-
Workshop, Family Room, Breakfast Area, Storage Area, Hot Tub, Recreation Room; Central Air, Fireplace, Gas Heat, Tile Floors; Lot Area: 3306; Lot Features: Swimming Pool, Car Garage, Cul-de-sac Location, Lot at Waterfront, Golf Course; Vicinity: Swimming Pool in the neighbourhood, Racquetball Court nearby
1350
6
2

-
Juliet Aubrey
1-439-668-4257
Juliet.Aubrey@talklist.com

2920600

-
-
MA
02163
Boston
3559 Kekeno Grove

-
Family Room, Study/Office, Laundry Room, Breakfast Area, Hot Tub, Storage Area; Central Air, Fireplace, Gas Heat, Tile Floors; Lot Area: 3585; Lot Features: Swimming Pool, Fenced Yard, Car Garage, Quiet Neighbourhood, Boat Facilities, Lot with Trees, Lot at Waterfront
1820
7
3

-
Christian Bale
1-638-108-1551
Christian.Bale@edson.net

4025800

-
-
CA
94112
San Francisco
6476 Macky St

-
Workshop, Family Room, Laundry Room, Eat-in Kitchen, Breakfast Area, Formal Dining Room, Guest Suite; Fireplace, Central Air, Gas Heat, Tile Floors; Lot Area: 1899; Lot Features: Fenced Yard, Cul-de-sac Location; Vicinity: Racquetball Court nearby, Golf in the neigbourhood, Tennis facilities in environment, Steam Room nearby
1640
7
3

-
Ian Bannen
1-538-585-1608
Ian.Bannen@yahoo.com

3522800

-
-
MA
02163
Boston
4789 Mansfield St

-
Workshop; Gas Heat; Lot Features: Quiet Neighbourhood; Vicinity: Swimming Pool in the neighbourhood, Tennis facilities in environment
1830
3
2

-
Alan Bates
1-588-693-8578
Alan.Bates@sailmail.com

3969000

-
-
CA
94112
San Francisco
1907 Moturoa St

-
Formal Dining Room; Central Air, Tile Floors; Lot Features: Corner Lot; Vicinity: Racquetball Court nearby, Golf in the neigbourhood
520
3
1

-
Sean Bean
1-814-826-9215
Sean.Bean@enote.com

1249800

-
-
IL
60665
Chicago
4099 Pine Tree Lane

-
Workshop, Laundry Room, Recreation Room; Central Air, Tile Floors; Lot Area: 1721; Lot Features: Car Garage, Cul-de-sac Location, Corner Lot, Lot at Waterfront; Vicinity: Swimming Pool in the neighbourhood
1380
6
2

-
Kate Beckinsale
1-298-955-1548
Kate.Beckinsale@123mail.net

3100400

-
-
DC
20599
Washington
7947 Shackleton Grove

-
Eat-in Kitchen; Fireplace; Lot Features: Swimming Pool, Fenced Yard; Vicinity: Golf in the neigbourhood
700
2
1

-
Ken Bones
1-553-453-5236
Ken.Bones@automailer.com

1510400

-
-
CA
94112
San Francisco
2041 Stone St

-
Laundry Room, Eat-in Kitchen; Central Air; Lot Features: Cul-de-sac Location, Lot with Trees
700
2
1

-
David Bowie
1-838-776-2291
David.Bowie@domainmart.com

1596400

</xq:result>
- <ino:message ino:returnvalue=“0”>
ino:messagelineXQuery Request processed</ino:messageline>
</ino:message>
</ino:response>

The unfortunate thing is that it works for me in my environment!

The stack trace doesn’t look quite right to me - is there a ReadNextPage missing?

Obviously the exception should not be thrown. The ReadNextPage method (which calls ReadPage(bool)) should ONLY be called when a valid cursor has been returned by Tamino. In this case the GetCursor method should work without error.

So it seems like something “odd” is happening in your environment. It seems like there is an OK query response without cursor information? Is it possible for you to log the HTTP traffic?

Thank you for your reply, unfortunately I only have Microsoft Application Center Test which logs the traffic, but unfortunately it didn’t display the traffic between the web page and the xml server, so i am not able to log the traffic right now, but I will try to log it.

I also had some difficulties while inserting records using XQuery tool and Interactive Interface(which are also listed in the XQuery section of the discussion forum), again there were problems about cursors but at last they were solved when I didn’t specify the pos. in Result and Result size fields. I wonder if these things might be related to eachother due to something wrong in my system…

All I am trying to do is inserting and querying records to/from database using .NET for 2 and a half days, still couldn’t. I think that if SoftwareAG can provide more samples for .NET API, it will be very beneficial, especially web page examples instead of console applications.

You can normally get free HTTP sniffers off the internet. Typically you run them on a particular port and then point the thing you wish to monitor at that port and the sniffer intercepts the messages, forwards them and provides the responses. I have had problems in the past with the Perl HttpSniffer and Tamino.

The standalone C# applications should hopefully translate into web apps relatively easily.

Hi,
Thank you for the hint,
but now the system gives the same exception in the code you gave :slight_smile: .
I guess this means that the problem is not in the ItemIterator but in the QueryResponse.
The CLR Debugger showed the error at line:

Console.WriteLine(qr.GetSinglePage().OuterXml);

And this is the stack trace:

C:\TAMINO\TAMINO~1\SAMPLES\QUERYS~1\QUERYI~1\BIN\DEBUG>QueryItemIterator http://
ServerName/tamino/Test TestCollection input()/Property[@Category=‘Sell’] 5
Tamino URL = http://ServerName/tamino/Test, Collection = TestCollection, XQuery = in
put()/Property[@Category=‘Sell’], PageSize = 5

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at SoftwareAG.Tamino.Api.Response.ResponseHandler2.GetCursor()
at SoftwareAG.Tamino.Api.TaminoPageIterator.ReadPage(Boolean next)
at SoftwareAG.Tamino.Api.TaminoPageIterator.Next()
at SoftwareAG.Tamino.Api.TaminoItemIterator.Next()
at SoftwareAG.Tamino.QuerySamples.QueryItemIterator.Main(String[] args) in c:
\tamino\taminoapi4dotnet\samples\querysamples\queryitemiterator\queryitemiterato
r.cs:line 71

so what might be wrong with my query?

What happened to the Christine Zimmerman’s message?? :slight_smile:

It was deleted when a NullReference exception was suspected! :slight_smile:

I actually think that the XQuery being sent is at fault - i.e. it slightly wrong and NO data is being returned. It may refer to a non-existent element.

This should be apparent if a check of TaminoQueryResponse.HasData is done before iterating.

It appears that the iterator may not handle the “no data” case in a robust fashion! :rolleyes:

I just checked in my environment and if a non-existent element is queried it is still handled without an exception.

It would be really useful to know the response that your XQuery is receiving from Tamino (i.e. from an HTTP sniffer).

Again and again, thank you very much for your help, but still doesn’t work.
Yesterday I also checked hasdata and it returns true, today I just rewrited the code, and put a check for hasData, as you may see, the code continiues executing and enters the block of if and still giving the same error.


here is my new code, and the error is also attached below:


using System;

using System.Xml;
using System.Diagnostics;
using System.Collections;

using SoftwareAG.Tamino.Api;

namespace SoftwareAG.Tamino.QuerySamples
{
///


/// Demonstrates how to use the TaminoItemIterator class of the Tamino API to
/// iterate through a query result set. Each individual item in the list is accessed
/// as an XmlNode.
///

///
///
/// Usage: QueryItemIterator ‘Tamino URL’ ‘Collection’ ‘XQuery’ ‘PageSize’
///


/// Example: QueryItemIterator http://myserver/tamino/mydb APISimpleSamples input()/Property[@Category=‘Sell’] 5
///

///
/// If a nonzero pagesize is specified, the Tamino cursor is used. A Tamino cursor
/// cannot be used in mode TaminoConnectionMode.AutoCommit, therefore this example opens the
/// connection in mode TaminoConnectionMode.LocalTransaction.
///
///
public class QueryItemIterator
{

///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
// process args

string dbUrl = “http://ServerName/tamino/Test”;
string collection = “TestCollection”;
string xquery = “input()/Property[@Category=‘Sell’]”;
int pageSize = 5;


// create connection
TaminoConnection connection = new TaminoConnection(dbUrl);

// open connection
connection.Open(TaminoConnectionMode.LocalTransaction);

// begin transaction
TaminoTransaction tx = connection.BeginTransaction();

// create command for collection
TaminoCommand command = connection.CreateCommand(collection);

// do query
TaminoQuery query = new TaminoQuery(xquery);
TaminoQueryResponse qr = command.Query(query, pageSize);
if (qr.HasData)
{
Trace.Assert(qr.ReturnValue.Equals(“0”), qr.ErrorText);

Console.WriteLine( “------------------------------”);
Console.WriteLine(qr.GetSinglePage().OuterXml); // displays the error here
Console.WriteLine("------------------------------");

TaminoItemIterator itemIt = qr.GetItemIterator();

while(itemIt.Next())
{
XmlNode node = itemIt.GetNode();
Console.WriteLine(“Item[”+itemIt.AbsoluteIndex+"]: "+node.OuterXml);
}
// close the query result set
} // end if
qr.Close();

// close connection - this will commit the local transaction implicitly
connection.Close();
}
}
}


And here is the error:

C:\TAMINO\TAMINO~1\SAMPLES\QUERYS~1\QUERYI~1\BIN\DEBUG>QueryItemIterator
------------------------------

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at SoftwareAG.Tamino.Api.Response.ResponseHandler2.GetCursor()
at SoftwareAG.Tamino.Api.TaminoPageIterator.ReadPage(Boolean next)
at SoftwareAG.Tamino.Api.TaminoPageIterator.Next()
at SoftwareAG.Tamino.Api.TaminoQueryResponse.GetSinglePage()
at SoftwareAG.Tamino.QuerySamples.QueryItemIterator.Main(String[] args) in c:
\tamino\taminoapi4dotnet\samples\querysamples\queryitemiterator\queryitemiterato
r.cs:line 65

I will try using a sniffer if I manage to get permission from my system admin, But I think that it returns the information to .NET, but somehow something wrong is happening out there…

ok, I installed a sniffer and looked at the packages.
in one of the packages going from server to .net, I noticed this error message, also this is the last package sent to .net application before it throws the error.

<?xml.version=“1.0”.encoding=“UTF-8”.>
ino:response.xmlns:ino=“http://namespaces.softwareag.com/tamino/response2”.xmlns:xql="http://metalab.unc.edu/xql/"
ino:message.ino:returnvalue="8305"
ino:messagetext.ino:code="INOXIE8305"Invalid.cursor.handle</ino:messagetext></ino:message></ino:response>

Now, the good news is, I just deleted the pageSize parameter, and constructed the query without using pageSize parameter, and now the application executes, prints out the records etc. , but before it terminates, throws an error, which is

An unhandled exception of type ‘SoftwareAG.Tamino.Api.TaminoException’ occurred in taminoapi.dll

Additional information: TANPIE0001: Close operation failed: INOXME8555: Session error occurred. : A session id is required for _DISCONNECT…

Why does my xml server so problematic about this pageSize? :slight_smile: It didn’t insert records from interactive Interface when I specified pageSize too. Will I need to use this pageSize attribute when developing applications? If I need it, how can I use it? :slight_smile:

And why does the application can’t disconnect? Any ideas?
Thanks a lot again…

If you use a non-zero pagesize then the data will be handled in pages of that size (pagesize = number of elements per page).

If you use no pagesize or a pagesize of zero then ALL the data will come back as a single page.

The pagesize is useful if a large number of elements is to be handled.

What output do you get for the C# compiler if you just execute “csc” on a command line?

What version is the TaminoAPI.dll? I.e. what do you get if you right click on TaminoAPI.dll in Windows Explorer and do Properties->Version?

Here is the csc version:

Microsoft ® Visual C# .NET Compiler version 7.00.9466
for Microsoft ® .NET Framework version 1.0.3705
Copyright © Microsoft Corporation 2001. All rights reserved.

And tamino dll version is : 4.1.1.1
File Size is: 132 KB (135.168 bytes)

By the way, from the sniffer, I saw that the server successfully sends the sessionID and session key to the user, but gives an error when the user tries to disconnect…

Could you supply a copy of a complete HTTP trace of the conversation when you run the QueryItemIterator program? You should be able to attach a zip.

I have the same problem.

All the data seem to come back on a single page whatever you use for the pagesize…

I don’t understand why…

To use sized iterators you need be within a local transaction.