Welcome, Guest
Username: Password: Remember me
This forum is the place to discuss issues related to ReportPro, Xs2Ado, Vo2Ado, bBrowser and other 3rd party products
  • Page:
  • 1

TOPIC:

Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource 29 Sep 2021 05:27 #19740

  • elibrighton
  • elibrighton's Avatar
  • Topic Author


  • Posts: 6
  • 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.'
    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.
    oRs := oCmd:Execute(NIL,NIL,NIL)

    Could you please help me understand why this is not working?

    Please Log in or Create an account to join the conversation.

    Last edit: by elibrighton.

    Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource 29 Sep 2021 13:55 #19741

    • robert
    • robert's Avatar


  • Posts: 3600
  • 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

    Please Log in or Create an account to join the conversation.

    Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource 14 Apr 2022 00:43 #22166

    • ahope
    • ahope's Avatar


  • Posts: 3
  • 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:
    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.:
    [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();
    }

    Please Log in or Create an account to join the conversation.

    Last edit: by ahope. Reason: aded unit test sample code

    Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource 14 Apr 2022 10:32 #22170

    • robert
    • robert's Avatar


  • Posts: 3600
  • 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

    Please Log in or Create an account to join the conversation.

    Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource 19 Apr 2022 00:39 #22205

    • ahope
    • ahope's Avatar


  • Posts: 3
  • 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.

    Please Log in or Create an account to join the conversation.

    Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource 19 Apr 2022 07:57 #22206

    • robert
    • robert's Avatar


  • Posts: 3600
  • Alexander,
    I am glad that it works now.
    new __Usual(adoCommand)

    should also have worked.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Xs2Ado AdoRecordSet:Open() exception when using Command object for uSource 19 Apr 2022 08:37 #22207

    • ahope
    • ahope's Avatar


  • Posts: 3
  • the unit test fails with
    new __Usual(adoCommand)
    but passes with
    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#:
    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.

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1