abp icon indicating copy to clipboard operation
abp copied to clipboard

Tenant Connection-string switching Information

Open jacmiller12 opened this issue 6 years ago • 5 comments

Hello,

We are not able to understand when we change the tenant from UI how it will use the provided connection string from code perspective.

where is the code in tenant or in the different modules we would like to know?

Let's say:

when I am login without specifying the tenant it uses the default connection string provided in appSettings.json.

but when I specify the name of tenant it will use there own connection string right. so where the connection string is switching we would like to know the location/filename.

It will would be great if anyone provide the document for the same.

Thanks in Advance.

jacmiller12 avatar Jul 03 '20 12:07 jacmiller12

See https://docs.abp.io/en/abp/latest/Connection-Strings

realLiangshiwei avatar Jul 03 '20 12:07 realLiangshiwei

Hi @liangshiw ,

I have Implemented in http.host project for demo purpose only.

using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;

namespace Test.Demo
{
    [Dependency(ReplaceServices = true)]
    public class connectionTest : IConnectionStringResolver, ITransientDependency
    {
        private readonly ICurrentTenant _currentTenant;
        private readonly IServiceProvider _serviceProvider;

        public connectionTest(
            IOptionsSnapshot<AbpDbConnectionOptions> options,
            ICurrentTenant currentTenant,
            IServiceProvider serviceProvider)
            
        {
            _currentTenant = currentTenant;
            _serviceProvider = serviceProvider;
        }

        public string Resolve(string connectionStringName = null)
        {
            return "Server=(local)\\SQLEXPRESS_2016;Database=MsDemo_Identity;Trusted_Connection=True;MultipleActiveResultSets=true";
        }
    }
}

and resolve the dependency context.Services.Replace(ServiceDescriptor.Transient<IConnectionStringResolver, connectionTest>());

so I have implemented this way, but now the issue is I am getting debug point in every 1 minute without any activity, don't know why can you please me.

Thanks in advance.

jacmiller12 avatar Jul 03 '20 16:07 jacmiller12

Some background workers will call repository method. You should look at the call stack.

realLiangshiwei avatar Jul 04 '20 00:07 realLiangshiwei

Hello @liangshiw ,

we have created the whole new project and then copy the same above code still, we are getting the hit again and again (debug point)

I think this is an issue because whatever the things provided in the documentation we are following but still not able to resolve the issue.

@liangshiw Please check the call stack. image image

jacmiller12 avatar Jul 06 '20 06:07 jacmiller12

Some background workers will call repository method, you can see the BackgroundJobWorker.

image

This is the design, If you don't need background jobs, you can disable the background job system.

realLiangshiwei avatar Jul 06 '20 06:07 realLiangshiwei