The OpsContext.DataStore is more an abstraction over the database, so you would probably be better of making the SQL queries directly to the database.
If you do this from an extension application, you can new up a database connection with the EMC.Data.Sql.DatabaseConnection type, then you don't need to worry about credentials.
We typically encapsulate this in a factory, so it easily can be swapped out with a static SQL DB Connection, when debugging the extension outside of Simphony, or what ever the need is.
Code:
using System.Data;
using Contracts.Factories;
using SimphonyUtilities.Settings;
namespace Factories.DatabaseConnection
{
public class SimphonyDbConnectionFactory : IDbConnectionFactory
{
private readonly DatabaseSettings _databaseSettings;
public SimphonyDbConnectionFactory()
{
_databaseSettings = DatabaseSettings.GetDbSettingsSafe(DatabaseSettings.DatabaseAlias.Master);
}
public string DataStore => DatabaseSettings.GetDbSettingsSafe(DatabaseSettings.DatabaseAlias.LocalDb).DBCatalog;
public string CheckPostingDB => DatabaseSettings.GetDbSettingsSafe(DatabaseSettings.DatabaseAlias.CPServiceDb).DBCatalog;
public bool CheckPostingDbExists => DatabaseSettings.CheckDbSettingsExist(DatabaseSettings.DatabaseAlias.CPServiceDb);
public IDbConnection CreateConnection() => new EMC.Data.Sql.DatabaseConnection(_databaseSettings).Connection as System.Data.Common.DbConnection;
}
}
However, I would always recommend reading check details through the POS API, since the POS API will then handle splits, reopen, voided items, and so on - doing that in SQL is just a mess.
You can use the GetCheckDetail call for this, see more in the Transaction Services API documentation
link, it returns nicely formatted XML data.
But the sql query approach works fine to get information about the checks that should be read.