change db owner / set read_only with clone template .. ?
I realize I could do the subject tasks in a separate step using a number of different approaches -- but I'm curious why I can't during the cloning process with a template. The help files tell me that the template is run after the clone is created so the 'database' exists with the name it needs to be. As part of our compliance and standards, I set all new database owners to a non-transitory AD account; when the clone is created, the owner is the account which I'm using to run the image=>clone process. When I execute:
Best Answer
-
Panagis Posts: 9 Bronze 3Hello @don_don,
SQL Clone creates a temporary low privilege user account to run the template script. The only role of this account is the db_owner.
The first issue arises because this account hasn't permissions to alter the authorization of the database, and the second because at the last step it tries to delete the temporary user, but it can't since the database is read-only.
What I'd suggest is to create a PowerShell script that will call the Clone cmdlet and after that it will alter the authorization of the database and make it read-only.
Kind regards,
Panagis
Answers