I can't use EF because it doesn't work with Oracle (or the tutorials I have found are outdated and not usable).
I am planning on using ODP.Net or devart's driver.
What is the best way to use a connection string from appsettings.json?
Ive seen so many tutorials that are incomplete or don't work with Asp.Net Core 3.1
My controller
public class ReportController : Controller
{
private readonly ConnectionString myString;
public ReportController(IOptions<ConnectionString> connectionString)
{
myString = connectionString.Value;
}
public ActionResult Reporting_Totals()
{
string connectionString = myString.ToString();
DataTable dt = new DataTable();
using (OracleConnection oracleConnection = new OracleConnection())
return View();
}
ConnectionString class
public class ConnectionString
{
private string connectionString { get; set; }
// enable set in singleton property instance to work correctly.
//public static ConnectionString Instance { get; set; } = new ConnectionString();
//public string DatabaseConnection { get; set; }
}
My Startup class
public Startup(IConfiguration configuration)
{
Configuration = configuration;
//configuration.GetSection("ConnectionString").Bind(ConnectionString.Instance);
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<ConnectionString>(Configuration.GetSection("ConnectionStrings"));
services.AddControllersWithViews();
}
My appsettings.json
"ConnectionStrings": {
"DEV": "Server=myServer;Database=myDb1;Trusted_Connection=True;",
"PROD": "Server=myServer;Database=myDb2;Trusted_Connection=True;"