question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to dynamic modify the DbContext's ConnectionString in AppService?

See original GitHub issue
  • Abp package version:4.10.1.
  • base framework: .Net Core.

I need to connect to multiple external databases of ERP in Abp Modular. My method is dynamic modify the DbContext’s ConnectionString in AbpController of Web Project. The code is as follows:

var connectionStringBuilder = new DbConnectionStringBuilder();
...
var db = _dbContextResolver.Resolve<MyDbContext>(connectionStringBuilder.ConnectionString, null);
(Data processing code...)

But I think the best way should be in the Application Project’s AppService. My question is: How to realize the above code functions in the AppService?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
XbCorecommented, Dec 3, 2019

I found the solution, same as the control. In the AppService inject IDbContextResolver, by IDbContextResolver resolver the DbContext and change it’s ConnectionString. Thanks everyone…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically change connection string in Asp.Net Core
I was able to change the connection string for each request by moving the connection string logic into the OnConfiguring method of the...
Read more >
Configuring Entity Framework Core with Dynamic Connection ...
We need to handle dynamic connection strings. The idea is that different clients of our Web API need to have different databases.
Read more >
Change Connection String at Runtime in ASP.NET CORE
C# Tutorial - Change ConnectionString at Runtime with App.config | ... Setup the DbContext Class and Database Connection String | ASP.
Read more >
Change DB Context connection string dynamically in ASP. ...
I have created parameterized DBcontext with Dbconnectionstring Parameter, in this way we can pass connection string before binding Customer ...
Read more >
DbContext Lifetime, Configuration, and Initialization
This example registers a DbContext subclass called ApplicationDbContext as a scoped service in the ASP.NET Core application service provider ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found