Open Closed

Switch contexts in the module template #3817


User avatar
0
manuel42 created
  • ABP Framework version: v5.3.4
  • UI type: MVC
  • DB provider: EF Core / MongoDB
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:" download Module template and set two connection string one for sql server and one for mongo db

Hello how can I switch between sql server and mongo db in the module template? Currently when I start the module template only the sql server Database is used for the application. When I change the default connectionstring to the mongoDb connection string I got an error.

I guess I need to change something in the ModuleName.Web.Unified

 public UnifiedDbContext CreateDbContext(string[] args)
    {
        var configuration = BuildConfiguration();

        var builder = new DbContextOptionsBuilder<UnifiedDbContext>()
            .UseSqlServer(configuration.GetConnectionString("Default"));

        return new UnifiedDbContext(builder.Options);
    }

and here


        Configure<AbpDbContextOptions>(options =>
        {
          options.UseSqlServer();
        });

My Appsetting

 {
  "ConnectionStrings": {
    "Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=DemoModule_Unified;Trusted_Connection=True",
    "Mongo": "mongodb://localhost:27017/DemoModule_Unified"
  }
}

2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Here is a sample you can check https://github.com/abpframework/abp/tree/dev/modules/blogging/app/Volo.BloggingTestApp.MongoDB

  • User Avatar
    0
    manuel42 created

    thank you this helps

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09