Msg 245, Level 16, State 1, Line 89
Conversion failed when converting the varchar value ‘There was an error creating the System.DirectoryServices assembly. ‘ to data type int.
This error is caused by the statement below:
begin try print ' - Preparing to create System.DirectoryServices assembly with UNSAFE_ACCESS permission'
create assembly [System.DirectoryServices] from 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll'
with permission_set = unsafe
print ' - System.DirectoryServices assembly created'
end try
begin catch
print 'There was an error creating the System.DirectoryServices assembly. '+Error_number()+Error_Severity()
end catch
This is coming from your concatenation of number to string in the
catchblock. This is not allowed without casting as it tries to convert the string to number rather than vice versa and as your string literal is not numeric this attempt is doomed to fail!You can use
RAISERRORwith severity 0 to print the message with the values substituted in or the alternative is to concatenate the string yourself using explicit casts.