Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

This forum is the place to discuss issues related to ReportPro, Xs2Ado, Vo2Ado, bBrowser and other 3rd party products
Post Reply
User avatar
elibrighton
Posts: 6
Joined: Wed Apr 05, 2017 11:15 pm

Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by elibrighton »

Hi,
I'm using version 5.0.4.0 of Xs2Ado in an XSharp project using the Vulcan dialect. I'm getting the following exception when passing a Command object for the uSource parameter to the AdoRecordSet:Open() method.

'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.'

Code: Select all

LOCAL oCommand AS AdoCommand
LOCAL oRs AS AdoRecordSet
...
oCmd := AdoCommand{}
oCmd:ActiveConnection := oConn
oCmd:CommandText := "SomeStoredProc"
oCmd:CommandType := AdCmdStoredProc
oRS := AdoRecordSet{}
oRs:Open(oCmd, Nil, adOpenForwardOnly, adLockReadOnly, adCmdStoredProc)

// Exception thrown
However, this same code worked in Vulcan.NET. I believe the Command object is valid because the expected AdoRecordSet is returned when using the AdoCommand:Execute() method for the same Command object. E.g.

Code: Select all

oRs := oCmd:Execute(NIL,NIL,NIL)
Could you please help me understand why this is not working?
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by robert »

Eli,
Can you mail me an example for this and the other problem you reported?

Robert at Xsharp dot Eu
XSharp Development Team
The Netherlands
robert@xsharp.eu
ahope
Posts: 3
Joined: Thu Apr 07, 2022 1:50 am

Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by ahope »

The problem here is that oRs:Open expects a ADODB.Command object as the first parameter. No derived classes seem to suffice.
Hence the error: 'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.'

Luckily the base class of the XSharp AdoCommand object exposes a .Interface member to access the underlying ADODB.Connection object.

So you just need to pass that member as a __Usual like this:

Code: Select all

oRs:Open(__Usual{oCmd.Interface}, Nil, adOpenForwardOnly, adLockReadOnly, adCmdStoredProc)
Here's a C# unit test i wrote to reproduce and resolve the issue, it uses the Ado objects from the XSharp library.:

Code: Select all

[TestMethod]
public void AdoCommand_SP_Noparam_XsRS()
{
	AdoConnection oConnection = GetConnetion();
	var ors = new AdoRecordSet();
	ors.CursorLocation = 3;
	AdoCommand adoCommand = new AdoCommand();
	adoCommand.ActiveConnection = oConnection;
	adoCommand.CommandText = "sp_tables";
	adoCommand.CommandType = 4;
	ors.Open(new __Usual(adoCommand.Interface), __Usual._NIL, 0, 1, 4);
	adoCommand.ActiveConnection = null;
	Assert.IsTrue(ors.RecordCount > 0);
	ors.Close();
	ors.Destroy();
}
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by robert »

Alexander,
The compiler should automatically take care of wrapping the command object in a USUAL.
Which version of the compiler are you using and which compiler options do you have selected ?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ahope
Posts: 3
Joined: Thu Apr 07, 2022 1:50 am

Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by ahope »

XSC.exe
Assembly Version 2.10.0.0
FileVersion 2.10.0.3
I reproduced using a c# unit test so i don't believe the compiler was the issue there. i updated the original post with my test.
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by robert »

Alexander,
I am glad that it works now.

Code: Select all

new __Usual(adoCommand)
should also have worked.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ahope
Posts: 3
Joined: Thu Apr 07, 2022 1:50 am

Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by ahope »

the unit test fails with

Code: Select all

new __Usual(adoCommand)
but passes with

Code: Select all

new __Usual(adoCommand.Interface)
I could also reproduce the error with a wrapper class that implemented the ADODB.Command interface, and not using any XSharp classes.
example in C#:

Code: Select all

using ADODB;
public class MyCommand : Command
{
        private readonly Command cmd = new Command();
        public object Interface { get=> cmd; }
        public Recordset Execute(out object RecordsAffected, ref object Parameters, int Options = -1)
        {
            return cmd.Execute(out RecordsAffected, ref Parameters, Options);
        }
...
}
When i pass this MyCommand object to the ADODB.Recordset.Open method it gets the same error.
Passing the MyCommand.Interface in to the ADODB.Recordset.Open method it gets no error.
So it looks like the the ADODB.Recordset class requires an ADODB.Command and not any class implementing the ADODB.Command interface.
User avatar
Kees Bouw
Posts: 119
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by Kees Bouw »

This is definitely not working as it is described in the documentation and as it was in Vo2Ado. Instead of

Code: Select all

oRS:Open(oCmd, NIL, adOpenStatic, adLockReadOnly, adCmdText)
I have to use

Code: Select all

oRS:Open(USUAL(oCmd:Interface), NIL, adOpenStatic, adLockReadOnly, adCmdText)
Not a big problem of course but it took a LONG time to figure it out (wish I had seen this topic earlier...)
In the Xs2Ado samples there is no sample that uses an AdoCommand object in AdoRecordSet:Open() so that was no help.

It is quite frustrating when the documentation c.q. Help file is not correct. When the Xs2Ado Help is opened even the title is wrong, it says "Vn2Ado".
Another random example: in the explanation of AdoCommand:Execute() there are examples in blue text, demonstrating 3 ways of using it. However, the second and third way are exactly the same so there must be 1 way missing.

Kees.
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by robert »

Kees,

I am sorry for the confusion.
As you may know, writing documentation is a LOT of work and most developers (including me) prefer to write code over documentation. ;)
If you have recommendations, please send these to me directly and I will incorporate the changes.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Kees Bouw
Posts: 119
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource

Post by Kees Bouw »

Robert,

The documentation is one thing but what worries me the most is that now for the second time in a few weeks I have spent literally days investigating a problem that turned out to be a bug or omission in Xs2Ado. The problem with USUAL(oCmd:Interface) was known on 14 April 2022 already (2 years ago!) when you wrote "The compiler should automatically take care of wrapping the command object in a USUAL." Why was this problem not fixed in the next release of Xs2Ado? That would have saved me and possibly others a lot of time. I do understand that creating new functionality in X# is more fun and more profitable but I would like to bring to the attention that it is also important to fix known bugs in existing products that are being used today in production environments.

Kees.
Post Reply