Vinit Vishwanathan
Vinit Vishwanathan

Reputation: 86

Issue while creating user for a specific database through code in Azure

I am creating a copy of database in Azure through c# code.

Code for creating database:

CREATE DATABASE ABC AS COPY OF DEF

Then I want to create a user in that database so that only that user can access the database. This code executes as soon as the database is created. but while creating a user I get an error:

"failed to update database because the database is read only".

If I stop the execution for 15-20 seconds, then start, it works perfectly, but I don't want to do that.

Can I get some status that the database is created and you can proceed.

Any help would be greatly appreciated.

Upvotes: 0

Views: 62

Answers (1)

Dan Rediske
Dan Rediske

Reputation: 852

It appears that you're connecting to your database and executing T-SQL, you may have to use a query against sys.dm_operation_status and find your Create Database command and whether it has completed. There may be an associated REST API if you choose to program this through REST calls, there is a Get Create or Update Server Status call which might fit your scenario.

You will find that the new database will take some time to create and you won't exit that logic instantly in either approach.

Upvotes: 2

Related Questions