Search code examples
sqlsql-servertsqlt

Could not find the type 'tSQLt.Private'


I have installed tSQLt with CLR permissions Off. I am not sure how it got installed. I see some stored procedure of class tSQLt. Now I am trying to re-install it by cleaning tSQLt, but could not able to do it.

When I run tSQLt.Uninstall it gives the below message

EXEC tSQLt.Uninstall
Msg 218, Level 16, State 1, Procedure Uninstall, Line 5
Could not find the type 'tSQLt.Private'. Either it does not exist or you do not have the necessary permission.

No I have ran the tSQLt.cleanup It give the following error.

Msg 3729, Level 16, State 1, Line 2
Cannot drop schema 'tSQLt' because it is being referenced by object 'NullTestResultFormatter'.

Can someone help me on this context


Solution

  • You can't uninstall tSQLt because tSQLt.Private type from tSQLtCLR assembly does not exists in your case (because you did not enable SQL CLR before installation).

    enter image description here

    select * from sys.assembly_types where assembly_class = 'tSQLtCLR.tSQLtPrivate'
    

    To re/un-install tSQLt in your case you need:

    1.Enable SQL CLR:

    EXEC sp_configure 'clr enabled', 1;
    RECONFIGURE;
    GO
    DECLARE @cmd NVARCHAR(MAX);
    SET @cmd='ALTER DATABASE ' + QUOTENAME(DB_NAME()) + ' SET TRUSTWORTHY ON;';
    EXEC(@cmd);
    GO
    

    2.Re-install tSQLt - simply execute sql script from tSQLt.class.sql (it drops and recreate all objects if they do exist)

    3.Un-install tSQLt (if you need)

    EXEC [tSQLt].[Uninstall]