Ok, I just took one of my old code libraries and updated it to Core 3.1 as a console app. Used the SAS OleDb provider. Ran it against the shoes dataset and produced the following:
Starting Test of SAS read...
Column: Region
Column: Product
Column: Subsidiary
Column: Stores
Column: Sales
Column: Inventory
Column: Returns
Completed...
I will try and clean the library up and make it a nuget package. For now, here is the code that illustrates what I am doing.
static void Main(string[] args)
{
WriteLine("Starting Test of SAS read...", Color.White);
var utils = new Utilities();
var ds = utils.GetDataSet(@"z:\scratch","shoes");
foreach (var c in ds.Columns)
{
WriteLine($"Column: {c}", Color.LightBlue);
}
WriteLine("Completed...");
ReadKey();
}
/// <summary>
/// Gets a SAS dataset from the specified location
/// </summary>
/// <param name="sasLibrary">The physical location of the SAS library to read in the data </param>
/// <param name="dataset">The name of the SAS dataset to read</param>
/// <returns>.NET datatable</returns>
public DataTable GetDataSet(string sasLibrary, string dataset)
{
OleDbConnection sas = null;
DataTable dt = new DataTable(dataset);
try
{
sas = new OleDbConnection(@"Provider=SAS.LocalProvider.1; Data Source=" + sasLibrary);
sas.Open();
OleDbCommand sasCommand = sas.CreateCommand();
sasCommand.CommandType = CommandType.TableDirect;
sasCommand.CommandText = dataset;
OleDbDataReader sasRead = sasCommand.ExecuteReader();
dt.Load(sasRead);
sas.Close();
}
catch (Exception ex)
{
sas.Close();
string errMessage = "Unable to get the SAS dataset. Library: " + sasLibrary + ", DataSet: " + dataset + ", " +
ex.TargetSite.Name;
HandleError(MethodBase.GetCurrentMethod().Name, ex);
}
finally
{
sas.Close();
}
return dt;
}
If the above code does not work, for you, in a console app, then you have other issues. I suspect IIS permissions. Look for my old blog "Sas: Out In Left Field" and I should have something out there addressing IIS usage. I have done that numerous times in the past. However, I don't use IIS anymore and rely on Kestrel for serving up pages. Consider doing that yourself and start moving away from IIS.
I have some notes on IIS I did so will put a few bits here to see if it loosens up some ideas.
Under Application Pools in IIS, click on the service name you are using, choose Advanced Settings, change Identity to LocalSystem.
Add the following 2 accounts to the directory where the dataset is located:
IIS APPPOOL\TheServiceName(or whatever you named it) NETWORK SERVICE
... View more