Click here to Skip to main content
15,305,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have done a Multi-tenancy application with a Separate database for separate Tenants. I have a problem with DB creation. 
If we get a new client, how do we create the DB? 
will we create DB Manually?
How do we alter the scripts? execute the script for all tenant DB manually? 

can we automate this? 

Please, anybody, have solutions or ideas for this Please share with me.  

What I have tried:

I tried this using for Dynamic DB  creation. This concept did not work in the azure servers.   we can create dynamically only in Development system. 
Updated 23-Sep-21 20:27pm

1 solution

There is a REST API available for Azure. For the database specific part, look here:
Azure SQL Database REST API reference | Microsoft Docs[^]

You also have a dotnet sdk. I found this example with a quick google search, so I do not know if it is up to date:
‘How to create an Azure SQL Database programmatically’ with less frustration · GitHub[^] - the namespaces etc in the sample should provide a starting point to find more information.

You will have to make sure your service is authenticated to create databases. I would look into Managed Identity: Managed identities for Azure resources | Microsoft Docs[^]
Then you avoid having to deal with keys that expire and other mess - but it will only work from a deployed azure service, not your dev-box. So as with everything security, it is complicated to find the least annoying way for your specific setup.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900