Hi,
So I was able to add a connection string to the file appsettings.json, but I can't find the way to retrieve it in my 'Service' C# code file which gets data from the DB.
What I could know is that I need an IConfiguration object, through whose GetConnectionString() method I would get the connection string, but ... from where do I get the IConfiguration object? Should I create one? Should I get it from certain place?
I have a 'Service' C# code file which gets data from the DB, like below:
Thank you.
Pablo
So I was able to add a connection string to the file appsettings.json, but I can't find the way to retrieve it in my 'Service' C# code file which gets data from the DB.
What I could know is that I need an IConfiguration object, through whose GetConnectionString() method I would get the connection string, but ... from where do I get the IConfiguration object? Should I create one? Should I get it from certain place?
I have a 'Service' C# code file which gets data from the DB, like below:
CountryService.cs:
public class CountryService
{
public List<Country> GetCountries()
{
SqlConnection conn = new SqlConnection(configuration.GetConnectionString("myConnection"));
...
...
}
}
Pablo