Open Closed

Can I choose different DB servers for different tenants? #4909


User avatar
0
portx-dev created

Can I choose different DB servers for different tenants?

At https://docs.abp.io/en/abp/latest/Multi-Tenancy#database-architecture, we have found that we can separate the DB for each tenant.

Can I choose different DB servers for different tenants?

Can I achieve the following? https://docs.abp.io/en/commercial/latest/modules/saas#connection-string

  • ABP Commercial: v7.1

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

    Hi,

    Sorry, but the ABP framework does not support it

  • User Avatar
    0
    portx-dev created

    Thank you very much.

    However, it occurs in the future that we want to separate DB instances. As a use case, ・Enterprise companies ・When the number of companies reaches a certain number, we want to split the DB (e.g. 1 DB instance per year)

    ●Question If we customize ABP Commercial to achieve this, can we get consulting? Also, is the scope of influence of customization quite large?

    ●workaround Given the current constraints, I would take the following approach ・xxx-2023.portx.cloud → 2023 DB ・xxx-2024.portx.cloud → 2024 DB

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    This sounds like a DBA thing.

    For the code side.

    you can dynamically replace the connect string.

    Server=localhost;Database=xxx-{year}.portx.cloud ;Trusted_Connection=TrueTrustServerCertificate=True

    [Dependency(ReplaceServices = true)]
    public class MyMultiTenantConnectionStringResolver: MultiTenantConnectionStringResolver
    {
        protected ICurrentTenant CurrentTenant { get; } 
        
        public MyMultiTenantConnectionStringResolver(IOptionsMonitor<AbpDbConnectionOptions> options, ICurrentTenant currentTenant, IServiceProvider serviceProvider) : base(options, currentTenant, serviceProvider)
        {
            CurrentTenant = currentTenant;
        }
    
        public async override Task<string> ResolveAsync(string connectionStringName = null)
        {
            var connectionString = await base.ResolveAsync(connectionStringName);
    
            if (CurrentTenant.IsAvailable)
            {
                connectionString = connectionString.Replace("{year}", DateTime.Now.Year.ToString());
            }
    
            return connectionString;
        }
    
        public override string Resolve(string connectionStringName = null)
        {
            var connectionString = base.Resolve(connectionStringName);
    
            if (CurrentTenant.IsAvailable)
            {
                connectionString = connectionString.Replace("{year}", DateTime.Now.Year.ToString());
            }
    
            return connectionString;
        }
    }
    
  • User Avatar
    0
    portx-dev created

    thank you.

    Is it possible to write the DB endpoint in this URL? https://docs.abp.io/en/commercial/latest/modules/saas?&_ga=2.31513790.1017473141.1680852494-480170447.1680614778#connection-string

    For example, for a company tenant, I want the host to be a.rds.cloud.

    Server=a.rds.cloud;Database=a;Trusted_Connection=TrueTrustServerCertificate=True
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Yes, you can.

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