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;
}
}
}
Thanks!