abp icon indicating copy to clipboard operation
abp copied to clipboard

Data is not stored to respective tenant database

Open saitejkuralla opened this issue 3 years ago • 13 comments

ABP Framework version 5.0

User Interface:MVC

database provider: EF Core

Steps needed to reproduce: I have followed the step-by-step process of: https://docs.abp.io/en/abp/latest/Multi-Tenancy and I have added the connection string details of each tenant in "AbpTenantConnectionStrings" and created databases of each tenant( Tenant1 & Tenant2 ) as TODOAPP1 & TODOAPP2 but when I save the data to database the data is stored in the default database (TODOAPP) but not in the tenant-specific database. am I missing anything here? How to configure Per tenant one database?

image

image

saitejkuralla avatar May 08 '22 13:05 saitejkuralla

Name is the name of the connectionstring. You can set Default for it.

JadynWong avatar May 08 '22 16:05 JadynWong

yes it is set to default only but the data is getting stored in the default connection/Database, not in the newly created databases (TODOAPP1 & TODOAPP2) image

saitejkuralla avatar May 09 '22 04:05 saitejkuralla

image

JadynWong avatar May 09 '22 05:05 JadynWong

Nope, I have changed it accordingly. it didn't work, data is not stored with the tenant-specific database. image

saitejkuralla avatar May 09 '22 06:05 saitejkuralla

I can not reproduce. Can you provide a simple project to reproduce it?

JadynWong avatar May 09 '22 14:05 JadynWong

sample code: https://github.com/saitejkuralla/TodoApp_Multitenancy

Below is the recent change in my code image

saitejkuralla avatar May 09 '22 14:05 saitejkuralla

sample code: https://github.com/saitejkuralla/TodoApp_Multitenancy

404 image

Below is the recent change in my code image

You don't need to modify AbpDbContext. Multi-Tenancy connectionstring switching in abp is out-of-the-box.

JadynWong avatar May 09 '22 14:05 JadynWong

updated the repo to "public" but without switching that I am unable to do that, could you help me out with that. the final requirement is to save the data in tenant specific database. By doing the above change the login credentials are part of the default database and I was unable to login now. Note : if there is any sample code for per tenant database that would be great

saitejkuralla avatar May 09 '22 15:05 saitejkuralla

  • Remove the changes you have made to AbpDbContext.

  • Please submit todo content after select a tenant.It is best to be able to login to the tenant user. Or use other ways of switching tenants (querystring, cookies, header, ...). https://docs.abp.io/en/abp/latest/Multi-Tenancy#tenant-resolvers

image

Host

image

Tenant1

image

querystring switch tenant

GIF

image

JadynWong avatar May 09 '22 16:05 JadynWong

sorry for this again the data is saved only in Default Database (TODOAPP) as tenant-specific. Yes using query string and switching the tenant I have submitted the data Am I missing anything here image

saitejkuralla avatar May 09 '22 16:05 saitejkuralla

I only removed your changes to AbpDbContext.

image

select AbpTenants.Id, AbpTenants.Name, AbpTenantConnectionStrings.Name, AbpTenantConnectionStrings.Value
from AbpTenants 
left join AbpTenantConnectionStrings on AbpTenants.Id = AbpTenantConnectionStrings.TenantId

image

JadynWong avatar May 10 '22 01:05 JadynWong

If the same code is not working for me hope it should be a bug .is that an environment issue?

saitejkuralla avatar May 19 '22 19:05 saitejkuralla

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 30 '22 17:07 stale[bot]