2011-04-08 7 views
0

메시지 수준 24, 수준 16, 상태 1, varchar 값을 변환 할 때 변환하지 못했습니다. 'System.DirectoryServices 어셈블리를 만드는 동안 오류가 발생했습니다. '을 데이터 유형 int로 변경하십시오.varchar를 int로 변환하는 중 오류가 발생 했습니까?

이 오류는 아래의 문에 의해 발생 :이 catch 블록에 문자열로 숫자의 당신의 연결에서 오는

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 

답변

2

. 캐스팅하지 않고 문자열을 숫자로 변환하려고 시도하기 때문에 캐스팅하지 않아도됩니다. 문자열 리터럴이 숫자가 아니기 때문에이 시도는 실패 할 운명입니다!

심각도가 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 
관련 문제