“Failed to install framework” error is encountered when installing tSQLt framework on a database

Applies to

ApexSQL Unit Test


When installing the tSQLt framework on a chosen database, in some cases the following warning message can be shown:

This can happen when either the chosen database is restored from a backup or the database owner SID is not listed/is not matched to any database SID record in the master database.


There is more than one solution to this issue. Here will be explained the two most common.


The first solution is already suggested in the raised message. In order to alter the authorization on the specific database, execute the following alter authorization statement against the database in question:

DECLARE @Command VARCHAR(MAX) = 'ALTER AUTHORIZATION ON DATABASE::[<<DatabaseName>>] TO [<<LoginName>>]'

SELECT @Command = REPLACE(REPLACE(@Command, '<<DatabaseName>>', SD.Name), '<<LoginName>>', SL.Name)
FROM master..sysdatabases SD
JOIN master..syslogins SL ON SD.SID = SL.SID

PRINT @Command

EXEC (@Command)

After this, the tSQLt framework should be installed in the chosen database without any issue.


The second solution has two steps. The first step is to map the specific user to the master database in SQL Server Management Studio. To do that, go to the Object Explorer pane, expand the Security node, then the Logins node. Navigate to the specific login and right-click on it. From the context menu, choose the Properties command:

Go to the User Mapping tab and tick the master database:

By default, the login user name will be added to the master database. Click the OK button.

The second and final step of this solution is to run the following script:

EXEC sp_changedbowner '<login_user_name>'

After applying either of the above-listed solutions, the tSQLt framework installation on the chosen database will result in this message:

Affected versions:

This issue affects all ApexSQL Unit Test versions since is not related to the add-in itself but the SQL Server settings.