Change database properties during image or clone creation
We want to use SQL test in conjunction with clones and want to make as simple for users to add SQL test to the clones as possible. Where we are having a tough time is setting the TRUSTWORTHY property of a clone by the time it is ready for use, as we are getting dinged for having insufficient permissions to run the statement, presumably due to limitations of the account used to create images and clones. Does anybody have a good workaround for this situation?
Cheers,
Matt
Cheers,
Matt
Tagged:
Answers
Sadly, you cannot make use the ability to apply any T-SQL modifications to either the image or clone, as SQL Clone runs these scripts creating a temporary user using db_owner permissions to apply the modification and to set the TRUSTWORTHY property requires sysadmin privileges.
Also if you use a backup file as the source of the image, the SQL Clone Agent creates a temporary database for the restore operation, SQL Server will set the TRUSTWORTHY property to off, as per this Microsoft article.
TRUSTWORTHY
option ON and you attach or restore the database to the same or another SQL Server instance, theTRUSTWORTHY
property will be set to OFF when attach or restore is completed.The only way for sure that the TRUSTWORTHY property can be set to on, is to manually do this once the clone has been created on the SQL Instance using a sysadmin account outside of SQL Clone. However, as this will cause a write to the differencing disk, it will increase the size of the Clone.
Many Thanks
Eddie
Senior Product Support Engineer
Redgate Software Ltd
Email: support@red-gate.com
Given what you've said, it's challenging to be able to combine clones with SQL test in such a way a person without highly elevated credentials could add SQL test to a clone they created. Do you have any other suggestions?
Cheers,
Matt
Thank you for reaching out to us with your concern. I understand that the limitations you mentioned with combining SQL Clone and SQL Test.
One solution that has worked for another client was to use tsqlt directly in their solution and add the tSQLtCLR assembly as a trusted assembly using the sys.sp_add_trusted_assembly stored procedure.
This allowed the user to run the SQL Test on the cloned database without requiring highly elevated credentials.
If this solution does not work for you, another option is to explore a PowerShell workaround to set the TRUSTWORTHY property on the cloned database. As Eddie mentioned this is a write change to the disk and would increase the size of the clone. This may be an acceptable change within your environment and allow SQL Test to function for the users.