Gettting data from external database

Hi!
I’m fairly new to Umbraco and struggle a bit to get my head around how to retrieve data from a external database.

I’ve been able to access that within the same database following this:

I’ve added a second connection string into the appsettings.json pointing to a sqllite db.

Then I’ve added the connection string to builder.Services:

using Microsoft.EntityFrameworkCore;
using bussbokning.Data;
using bussbokning.Controllers;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
var env = builder.Environment;
var config = builder.Configuration;

builder.Services.AddUmbraco(env, config)
    .AddBackOffice()
    .AddWebsite()
    .AddComposers()
    .AddDeliveryApi()
    .Build();
string connectionString = config.GetConnectionString("umbracoDbDSN2");
string connectionStringProvider = config.GetConnectionStringProviderName("umbracoDbDSN2");
Console.WriteLine("connectionString: " + connectionString);
Console.WriteLine("connectionStringProvider: " + connectionStringProvider);
builder.Services.AddUmbracoDbContext<DrivingOrderContext>(options => options.UseSqlite(connectionString));

WebApplication app = builder.Build();

await app.BootUmbracoAsync();


app.UseUmbraco()
    .WithMiddleware(u =>
    {
        u.UseBackOffice();
        u.UseWebsite();
    })
    .WithEndpoints(u =>
    {
        u.UseInstallerEndpoints();
        u.UseBackOfficeEndpoints();
        u.UseWebsiteEndpoints();
    });

await app.RunAsync();

But the controller still takes the defualt connection.

Clearly something that I don’t understand, hope someone can point me in the right direction.
Maybe this can be done better in some other way?


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/113814-gettting-data-from-external-database