it seems that the connection to my database is not working at all, but I don't know why.
So you can see the error right there :

& now let's see the code, appsettings.json :
"ConnectionStrings": {
"Web": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xx.xx.x.xxx)(PORT=xxxx))(CONNECT_DATA=(SERVICE_NAME=xxxxxxx)));User Id=xxxxx;Password=xxxxx;"
}
Startup.cs :
public void ConfigureServices(IServiceCollection services)
{
[...]
services.AddDbContext<ApplicationDbContext>(options =>
options.UseOracle(Configuration.GetConnectionString("Web")));
[...]
}
HomeController.cs :
public class HomeController : Controller
{
[...]
private readonly CoreDataBase dataBase = new CoreDataBase();
[...]
}
CoreDataBase.cs :
public class CoreDataBase : IDisposable
{
private IDatabase _core = null;
public CoreDataBase()
{
_core = Load();
}
private static Database Load()
{
var connectionString = ConfigurationManager.ConnectionStrings["Web"].ConnectionString;
var provider = ConfigurationManager.ConnectionStrings["Web"].ProviderName;
if(provider != "Oracle.ManagedDataAccess.Client")
{
return null;
}
return new Database(connectionString, DatabaseType.OracleManaged, SqlClientFactory.Instance);
}
[...]
}
Do you have any idea ?
ConfigurationManagerdon't get value from appsettings.json, but from App.config or Web.config. You need rewriteCoreDataBaseto inject connection string settings.appsettings.json, not same as theWeb.configused in ASP.NET project. You can read these data fromappsettings.jsonfile via an instance of IConfiguration that you injected.