I am trying to automate the tenant DB creation in Azure SQL Server. DB has been created/copied as
CREATE DATABASE {0} AS COPY OF {1} ( SERVICE_OBJECTIVE = 'S2' )
Immediately adding a record to one of the table in the same. Getting error as:
Function completed (Failure, Id=1046eae2-c07a-4eee-9a1d-886e89ab5071) A ScriptHost error has occurred Exception while executing function: Functions.CreateTenant. .Net SqlClient Data Provider: Database 'tenant8' on server 'dbserver' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '8AF58081-8F25-4B7F-83E3-63AFFC13C8CB'. Exception while executing function: Functions.CreateTenant Executed 'Functions.CreateTenant' (Failed, Id=1046eae2-c07a-4eee-9a1d-886e89ab5071) Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID is '1046eae2-c07a-4eee-9a1d-886e89ab5071'
Looking at the error message, it seems that you are trying to insert data before the database
tenant8
has been provisioned and deployed. Deploying a database takes any time between a few dozens seconds to a few minutes. A description of the steps involved in this operation can be found on this blog post by Steve Mark. Please let us know if the deployment takes more than 5 minutes.