Page 1 of 1
Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Wed Sep 29, 2021 3:27 am
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.
Could you please help me understand why this is not working?
Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Wed Sep 29, 2021 11:55 am
by robert
Eli,
Can you mail me an example for this and the other problem you reported?
Robert at Xsharp dot Eu
Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Wed Apr 13, 2022 10:43 pm
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();
}
Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Thu Apr 14, 2022 8:32 am
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
Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Mon Apr 18, 2022 10:39 pm
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.
Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Tue Apr 19, 2022 5:57 am
by robert
Alexander,
I am glad that it works now.
should also have worked.
Robert
Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Tue Apr 19, 2022 6:37 am
by ahope
the unit test fails with
but passes with
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.
Re: Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Tue Mar 12, 2024 10:46 am
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.
Re: Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Tue Mar 12, 2024 11:36 am
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
Re: Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource
Posted: Wed Mar 13, 2024 8:23 am
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.