Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

App not seeding Apb tables on startup. #5287


User avatar
0
epiphanybsg created

I got the app up and running. Started up, it was working fine. I checked in the code, and when another developer started the app (database is created and tables exist) he gets the following error:

There is no tenant with given id: 1 Abp.MultiTenancy.TenantCache<TTenant, TUser>.Get(int tenantId) in TenantCache.cs, line 35

I don't remember doing anything specific when I first started the app. When I look in my database, I have a record in AbpTenant, when he looks in his, there is no record. Any ideas?

Thanks,

Matt


7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Is the primary key id of the data in the Abp Tenants table a number 1?

    If you are just starting the project, you can delete the database and re-migrate.

  • User Avatar
    0
    epiphanybsg created

    It is a fresh database, all they have done is run Update-Database, and then start the application.

  • User Avatar
    0
    maliming created
    Support Team

    Can you share the complete stack information?

    You can try to modify the database name of the database connection string, re-migrate and start the application to see if it is still wrong.

  • User Avatar
    0
    epiphanybsg created
    An unhandled exception occurred while processing the request.
    AbpException: There is no tenant with given id: 1
    
    Abp.MultiTenancy.TenantCache<TTenant, TUser>.Get(int tenantId) in TenantCache.cs, line 35
       at Abp.MultiTenancy.TenantCache`2.Get(Int32 tenantId) 
        in D:\\Github\\aspnetboilerplate\\src\\Abp.Zero.Common\\MultiTenancy\\TenantCache.cs:line 35
        at Castle.Proxies.Invocations.TenantCache`2_Get.InvokeMethodOnTarget()
        at Castle.DynamicProxy.AbstractInvocation.Proceed()
        at Castle.DynamicProxy.AbstractInvocation.Proceed()
        at Castle.Proxies.TenantCache`2Proxy.Get(Int32 tenantId)
        at Abp.Zero.EntityFrameworkCore.DbPerTenantConnectionStringResolver.GetNameOrConnectionString(DbPerTenantConnectionStringResolveArgs args) 
            in D:\\Github\\aspnetboilerplate\\src\\Abp.ZeroCore.EntityFrameworkCore\\Zero\\EntityFrameworkCore\\DbPerTenantConnectionStringResolver.cs:line 50
        at Abp.Zero.EntityFrameworkCore.DbPerTenantConnectionStringResolver.GetNameOrConnectionString(ConnectionStringResolveArgs args) 
            in D:\\Github\\aspnetboilerplate\\src\\Abp.ZeroCore.EntityFrameworkCore\\Zero\\EntityFrameworkCore\\DbPerTenantConnectionStringResolver.cs:line 45
        at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.GetOrCreateDbContext[TDbContext](Nullable`1 multiTenancySide) 
            in D:\\Github\\aspnetboilerplate\\src\\Abp.EntityFrameworkCore\\EntityFrameworkCore\\Uow\\EfCoreUnitOfWork.cs:line 107
        at Abp.EntityFrameworkCore.Uow.UnitOfWorkDbContextProvider`1.GetDbContext() 
            in D:\\Github\\aspnetboilerplate\\src\\Abp.EntityFrameworkCore\\EntityFrameworkCore\\Uow\\UnitOfWorkDbContextProvider.cs:line 28
        at EBSG.CrmDemo.EntityFrameworkCore.DatabaseCheckHelper.Exist(String connectionString) 
            in C:\\git_src\\CRM\\ANZ\\src\\EBSG.CrmDemo.EntityFrameworkCore\\EntityFrameworkCore\\DatabaseCheckHelper.cs:line 36
    
  • User Avatar
    0
    maliming created
    Support Team

    It seems that what caused the tenant 1 does not exist.

    please send your project to <a href="mailto:[email protected]">[email protected]</a>. This will help to quickly locate the problem. :)

  • User Avatar
    0
    epiphanybsg created

    Thanks for your help on resolving this problem. I'm posting the solution for others who may also experience this issue.

    **Hi,

    Thank you for sharing your solution. It seems like there is a bug for single tenant mode.

    Please change Exist method of DatabaseCheckHelper class (which is under src\xxx.EntityFrameworkCore\EntityFrameworkCore) like below;**

    public bool Exist(string connectionString)
    {
    	if (connectionString.IsNullOrEmpty())
    	{
    		//connectionString is null for unit tests
    		return true;
    	}
    
    	try
    	{
    		using (var uow =_unitOfWorkManager.Begin())
    		{
    			using (_unitOfWorkManager.Current.SetTenantId(null))
    			{
    				_dbContextProvider.GetDbContext().Database.OpenConnection();
    				uow.Complete();
    			}
    		}
    	}
    	catch (Exception ex)
    	{
    		return false;
    	}
    
    	return true;
    }
    
  • User Avatar
    0
    alper created
    Support Team

    thanks for your feedback ;)