3

I want to setup oracle database settings in appsetting.json file in my .netcore application my previous datasource structur like this in Asp.Net

<oracle.manageddataaccess.client>
    <version number="*">
      <dataSources>
        <dataSource alias="Test" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=180.148.11.140)(PORT=1221))(CONNECT_DATA=(SERVICE_NAME=orcl))) "/>
      </dataSources>
    </version>
  </oracle.manageddataaccess.client>
  <connectionStrings>
    <add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client"
      connectionString="User Id=Emp;Password=abc@123;Data Source=Emp"/>

  </connectionStrings>
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Jay
  • 703
  • 9
  • 21
  • Possible duplicate of [Store / Retrieve ConnectionString from appSettings.json in ASP.net Core 2 MVC app](https://stackoverflow.com/questions/50507382/store-retrieve-connectionstring-from-appsettings-json-in-asp-net-core-2-mvc-ap) – Panagiotis Kanavos Sep 25 '18 at 13:43
  • I want to handle **dataSource** provided inside `` i all ready know how to get `` and access to dbcontaxt or other pages please try to understand my promble.@PanagiotisKanavos – Jay Sep 25 '18 at 13:46
  • Those are just tags. Create the *same* sections in the JSON file and read them just like any other setting. There are no special paths or tags in .NET Core. Perhaps you wanted to ask something different, like how to have the Oracle client configure itself from those settings? – Panagiotis Kanavos Sep 25 '18 at 13:48
  • ok than how i handle this tag in json file? – Jay Sep 25 '18 at 13:50
  • 1
    That's a JSON question, not related to settings. You specify it the same way as any other object in JSON - as a dictionary whose keys are the property names, values are the property contents. Eg: `"version" : { "number" : "*"} ,...`. You *don't* have to follow the same structure though. Create a configuration class in the shape you want and write the JSON text in a way that matches it. An `OracleSettings` class with a Version, Alias and Descriptor string properties would be enough. That maps easily to an `"OracleSettings": { Version=*", Alias="Test", Descriptor="...."}` – Panagiotis Kanavos Sep 25 '18 at 13:54
  • thanks i will try its... – Jay Sep 25 '18 at 13:56
  • did you got this working using the appsettings.config? – Kenny Tordeur Jan 24 '19 at 12:24

0 Answers0