Issue loading data with an IEFCoreScopeProvider and an external database #16843
Replies: 2 comments
-
I have just noticed that a fellow Umbraco user is having the same issue: https://our.umbraco.com/forum/using-umbraco-and-getting-started/113814-gettting-data-from-external-database |
Beta Was this translation helpful? Give feedback.
-
Hello there 👋 I just had a talk with the team about this. For now, we don't support external database sources to be used with our Scopes, the regular In the future, it would be really cool to support multiple data sources, but for now it is not an option 😁 You can however just use the DbContext as you would normally! I will go ahead and mark this as a feature request 😁 |
Beta Was this translation helpful? Give feedback.
-
Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)
13.4.1
Bug summary
We need to access data stored in a completely separate database so we add a new context using the
AddUmbracoDbContext
extension method and set the connection string in the options. This works as expected when running migrations to build the database from the models but it fails when attempting to retrieve data.Specifics
We have two connection strings in the app settings: One pointing to a DB called UmbError (which holds all the Umbraco tables) and another pointing to UmbErrorExternal (an entirely separate database that will hold custom data - movies in our example)
We add the context for the external database in a composer that references our external DB connection string. As mentioned in the summary, creating the tables using migrations works as expected. However, when we try to use this context to retrieve data, the context always seems to have the connection string of the Umbraco database, causing Entity to fail to find our tables.
Shown above is our injection of
IEFCoreScopeProvider<MovieContext>
and an inspection of the injected object having the connection string for the UmbError table where we expect it to be UmbErrorExternalSteps to reproduce
Sample code with clean Umbraco and minimal steps is available here: https://github.com/NobleMule/UmbExternalDBIssue
To reproduce manually:
Expected result / actual result
The expected result (if using the linked sample repo) is that the API endpoint at /api/movies/ returns a collection of movies and their genres
The actual result is we get an error stating that our table cannot be found (which is due to the connection string pointing to a different DB to the one we want
Beta Was this translation helpful? Give feedback.
All reactions