Open Closed

Unable to add connection strings to new tenants #5216


User avatar
0
jasenfici@gmail.com created
  • ABP Framework version: v7.2.2

  • UI type: MVC

  • DB provider: EF Core

  • Tiered (MVC) or Identity Server Separated (Angular): yes

  • Steps to reproduce the issue:

I'm pretty sure this is a bug, so I never know if I should be posting it here, in the GitHub abp issues repository, or the discussion, hope this is the right place.

We create new tenants on cusomter registration, and we have a few entities that are accessed via MongoDb instead of SQL, so we need to add a secondary connection string to the SaaSTenantConnectionStrings table. Right now we have tried two ways to make this happen and neither seem to work:

Attempt 1:

var tenant = await base.CreateAsync(new Volo.Saas.Host.Dtos.SaasTenantCreateDto
    {
        ActivationEndDate = DateTime.UtcNow.AddDays(14),
        ActivationState = TenantActivationState.ActiveWithLimitedTime,
        EditionId = editionId,
        Name = dbName,
        AdminEmailAddress = $"-redacted-",
        AdminPassword = _$"-redacted-",
        ConnectionStrings = new Volo.Saas.Host.Dtos.SaasTenantConnectionStringsDto
        {
            Default = defaultDb,
            Databases = new List<SaasTenantDatabaseConnectionStringsDto>()
            {
                new SaasTenantDatabaseConnectionStringsDto
                {
                    DatabaseName = "MongoDb",
                    ConnectionString = mongoDb
                }
            }
        }
    })

This results in only the default database being created, the MongoDb connectionstring is never inserted.

So post-tenant creation we are now trying this as well:

var stcsDto = new SaasTenantConnectionStringsDto();
stcsDto.Default = defaultDb;
stcsDto.Databases = new List<SaasTenantDatabaseConnectionStringsDto>()
{
    new SaasTenantDatabaseConnectionStringsDto
    {
        DatabaseName = "MongoDb",
        ConnectionString = mongoDb
    }
};
await base.UpdateConnectionStringsAsync(tenant.Id, stcsDto);

This also doesn't seem to insert the MongoDb connectionstring.

If we are using this wrong, please let me know the best way to insert a secondary connection string (assume there's a repository?) I was just trying to use what I assume is the best practice. I don't see any documentation on these calls so we are kind of inferring their usage. What is the intended outcome of both these calls? What SHOULD we do to create the secondary entry?

thank you, jasen


5 Answer(s)
  • User Avatar
    0
    jasenfici@gmail.com created

    Update: Using a direct repository to IRepository<TenantConnectionString> works:

    await _tenantConnectionStringRepository.InsertAsync(new TenantConnectionString(tenant.Id,"MongoDb", mongoDb));

    However, it seems that this shouldn't be required if the SaaSTenantCreateDto class supports a list.

  • User Avatar
    0
    jfistelmann created

    Hey Jasen,

    sorry that you're experiencing troubles. Can you maybe share the complete file with me? I will then try to reproduce and debug it. If it's a bug, we'll of course refund the ticket.

    kind regards Jack

  • User Avatar
    0
    jasenfici@gmail.com created

    Hi that code is wrapped up in an entire email confirmation process for us so there is nothing I can really share. The snippet I provided above IS standalone though you should be able to just inject the abp TenantService anywhere as a quick test, then call Create with an additional connectionstrings.

  • User Avatar
    0
    jfistelmann created

    Hi that code is wrapped up in an entire email confirmation process for us so there is nothing I can really share. The snippet I provided above IS standalone though you should be able to just inject the abp TenantService anywhere as a quick test, then call Create with an additional connectionstrings.

    Okay understood. I'll try my best and keep you updated

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The Databases of SaasTenantCreateDto is used for the below UI feature

    we need to add a secondary connection string to the SaaSTenantConnectionStrings table

    You can use repository in your case.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35