Sql server 2008 将varchar转换为int时出错?
Msg 245,16级,状态1,第89行 转换varchar值“创建System.DirectoryServices程序集时出错”时,转换失败到数据类型int 此错误由以下语句引起:Sql server 2008 将varchar转换为int时出错?,sql-server-2008,Sql Server 2008,Msg 245,16级,状态1,第89行 转换varchar值“创建System.DirectoryServices程序集时出错”时,转换失败到数据类型int 此错误由以下语句引起: begin try print ' - Preparing to create System.DirectoryServices assembly with UNSAFE_ACCESS permission' create assembly [System.DirectoryServices] from
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
这是从
catch
块中的数字到字符串的串联得到的。不强制转换是不允许的,因为它试图将字符串转换为数字,而不是将字符串转换为数字,并且由于字符串文字不是数字,因此此尝试注定会失败
您可以使用严重性为0的RAISERROR
打印带有中替换值的消息,或者使用显式强制转换连接字符串
begin catch
declare @num int = Error_number()
declare @sev int = Error_Severity()
raiserror('There was an error creating the System.DirectoryServices assembly. %d %d ',0,1, @num,@sev)
end catch