1. Sabir Foux
  2. SnapObjects
  3. Tuesday, 10 September 2019 05:18 AM UTC

Problem: Any value I pass to the Retrieve(argument) method returns the error below. I can't tell why.

I've tried different data types in the database I need to pull records from. I've tried to use Guids, strings, number types, etc, but none of them worked. 

I'm reaching out here in case anyone knows what may be the cause & solution. I've inserted my code below just in case.

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: arguments
   at PowerBuilder.Data.AdoDbDataSource`1.Retrieve(Object[] arguments)
   at PowerBuilder.Data.DataStore`1.Retrieve(Object[] arguments)
   at WebApi.Services.Impl.DSSQLMasterDBService.RetrieveByKey(Int64 ConnectionID) in C:\Appeon\Repositories\WebApi\Services\Impl\DSSQLMasterDBService.cs:line 31
   at WebApi.DataContextFactoryNETDataStore.GetKeyByDataBase() in C:\Appeon\Repositories\WebApi\WebApi\DataContextFactoryNETDataStore.cs:line 78


Service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PowerBuilder.Data;

namespace WebApi.Services.Impl
{
    public class DSSQLMasterDBService : IDSSQLMasterDBService
    {
        private readonly DefaultDataContext _dataContext;
        
        public DSSQLMasterDBService(DefaultDataContext dataContext)
        {            
            _dataContext = dataContext;
        }


        public IDataStore RetrieveByKey(long ConnectionID)
        {
            var dataStore = new DataStore("d_masterdb_connection", _dataContext);
            
            dataStore.Retrieve(ConnectionID);

            return dataStore;
        }
    }
}


Data Factory
using WebApi.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using PowerBuilder.Data;
using SnapObjects.Data.Odbc;
using System;
using WebApi.Services;
using WebApi.Services.Impl;

namespace WebApi
{
    public class DataContextFactoryNETDataStore
    {
        IConfiguration _config;
        IHttpContextAccessor _httpAccessor;
        private IDSSQLMasterDBService _service;

        public DataContextFactoryNETDataStore(IConfiguration config, IHttpContextAccessor httpAccessor, IDSSQLMasterDBService service)
        {
            _config = config;
            _httpAccessor = httpAccessor;
            _service = service;
        }

        public DataContextBaseNETDataStoreOdbc CreateDataContextSQL()
        {
            var connectionString = _config["ConnectionStrings:MasterDB"];

            var options0 = new OdbcDataContextOptions(connectionString);

            var context = new DefaultDataContext(options0);

            _service = new DSSQLMasterDBService(context);

            //para obtener las cadenas de conexion del archivo appsettings.json
            //string connectStr = _config["ConnectionStrings:" + GetKey()];

            //para obtener las cadenas de conexion desde una base de datos
            string connectStr = GetKeyByDataBase();

            var options = new OdbcDataContextOptions(connectStr);

            return new DataContextBaseNETDataStoreOdbc(options);
        }

        private string GetKey()
        {
            // obtiene el parametro desde la URL 
            var key = _httpAccessor.HttpContext.Request.Query["connectionID"].ToString();

            if (key == null || key == "")
            {
                key = "MasterDB";
            }

            return key;
        }

        private string GetKeyByDataBase()
        {
            // obtiene el parametro desde la URL 
            // String connectionID = _httpAccessor.HttpContext.Request.Query["connectionID"].ToString();

            //para obtener las cadenas de conexion desde el Header
            String connectionText = _httpAccessor.HttpContext.Request.Headers["connectionID"].ToString();
            long connectionID;
            long.TryParse(connectionText,out connectionID);
            
            String connectionString = "";

            if (connectionID == 0)
            {
                connectionID = 1; //This is the MasterDB Guid
            }

            try
            {
                var model = _service.RetrieveByKey(connectionID);


                if (model == null)
                {
                    connectionString = _config["ConnectionStrings:MasterDB"];
                }
                else
                {
                    connectionString = model.GetItem(0, "ConnectionString").ToString();
                    if (String.IsNullOrWhiteSpace(connectionString)) 
                    {
                        connectionString = model.GetItem(1, "ConnectionString").ToString();
                    }
                }

            }
            catch (Exception ex)
            {
                return ex.ToString();
            }


            return connectionString;
        }

    }
}
Accepted Answer
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 10 September 2019 09:40 AM UTC
  2. SnapObjects
  3. # Permalink

Hi Sabir,

Please check your retrieve arguments defined in DataWindow object d_masterdb_connection. Maybe there are more than one argument defined there.

Regards,

Logan

Comment
  1. Sabir Foux
  2. Wednesday, 11 September 2019 05:28 AM UTC
Thanks Logan, the problem was that the argument was not defined for this particular DataWindow object. I now have connectivity going and I'm able to call the web api through Postman or my browser.

Thanks!
  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Tuesday, 10 September 2019 14:03 PM UTC
  2. SnapObjects
  3. # 1

What happens if you hard code a  >>> 1 <<< in place of the "connectionID" parameter?

Olan

Comment
There are no comments made yet.
Olivier PAVLIN Accepted Answer Pending Moderation
  1. Monday, 18 November 2019 15:26 PM UTC
  2. SnapObjects
  3. # 2

Hi I have exactly the same problem as you to retreive a record in my database by ID (which is a string value).

But i did define a retrieval argument (as string) for this Datawindow (screenshot1) and still get an ArgumentOutOfRangeException using my web api with an argument.

You can see my model (screenshot2), my service (screenshot3), my controller (screenshot4) and the resulting error when passing the api/../argumentvalue by http:// (screenshot5)

Thank you for your help if you already resolved this issue.

Attachments (5)
Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.