Base solution for your next web application
Open Closed

New Tenant in Different Database #8418


User avatar
0
-bitman created

Hello AspNetZero Team,

My apologies for a newbie question. I am trying to create a new tenant using the Tenant Management page and I wanted to use a different database for this new tenant. Under the Database connection string input field I entered the same connection string as my host except for the database name but the app is throwing an internal server error. I already went ahead and created an empty database with the same name for the new tenant but the same error is thrown. Please advise if I am missing anything?

Thank you!


6 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, can you share the ANZ version and framework?

    also, the error stack trace for new tenant creation?

  • User Avatar
    0
    -bitman created

    I think I figured it out. It has something to do with my connection string where the database must be created already in the backend and use SQL Authentication instead of Windows Authentication for better security and elevated permission. The only thing I am concerned though is that I need to manually create the new tenant database first before the migration happens. I wanted this to be part of the automated, non-user interactive approach. My use case is that, I will be having a registration page for new companies and I want them to be in their own database but I don't want to do that manually myself. Is there a way to accomplish this without user intervention?

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, if you are using sql authentication for the connection string, please make sure the authentication has the correct permission to create database.

    you can test it out using sa authentication for the connection string and it should create a database with the name provided.

  • User Avatar
    0
    -bitman created

    Yes that's what I did actually. I used sa and even created a new login with all permissions just to confirm the issue. When the database I want created is not existing in SQL Server, creating the new tenant does not work and throws an internal server error. But if I create the database prior to creating the tenant, it works. Now checking the Audit Log, I can see that the issue is this...

    Microsoft.Data.SqlClient.SqlException (0x80131904): CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Users\administratorSonetaDb-myDb.mdf'. CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

    If it helps, I am using MSSqlLocalDb edition of MS SQL Server.

  • User Avatar
    0
    musa.demir created

    Hello @ramilcatalandomingo

    You can run the [YourProjectName].[YourTemplateName].Migrator project. It creates all databases, (for tenants and host). By the way, Make sure the machine you run migrator is allowed to connect that SQL servers.

  • User Avatar
    0
    -bitman created

    Thank you for your response @demirmusa.