2012-05-01 2 views
5

때때로 저장 프로 시저 마녀를 작성했습니다. RAISERROR(). 내가 좋아하는 엔티티 프레임 워크를 통해 실행합니다엔티티 프레임 워크에서 데이터베이스 오류 처리

using(MyModelEntities conn = new MyModelEntities()) { 
    conn.MyStoredProcedure(input_p, output_p); 
} 

저장 프로 시저 :

create procedure dbo.MyStoredProcedure(
    @input nvarchar(255), 
    @output int out 
) 
as 
begin 
    ... 
     RAISERROR (N'My Exception....', 10, 1); 
    ... 
end 
go 

이 오류에 대한 정보를 얻을 수있는 기회가 있습니까?

답변

2

예외가 표시된 상태에서 try/catch에 넣을 수 있습니까? 아니면 디버그 모드로 전환 할 수 있습니까? 여기

+0

Btw. 너무 빠르다 ... RAISERROR가 예외를 반환하지 않습니다. Sql Server Erorrs 만 ... 그렇다면 사용자 정의 오류를 어떻게 처리 할 수 ​​있습니까? – nosbor

+1

Try/Catch 블록에서 SqlException의 인스턴스를 catch하고 있습니까? 또는 Messsage 또는 Errors 속성을 사용하고 있습니까? (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.aspx) –

0

내가이 처리하는 방법입니다

create procedure dbo.MyStoredProcedure(
    @input nvarchar(255), 
    @output text out 
) 
as 
begin 
    ... 
     SELECT @message = convert(varchar, getdate(), 108) + ': My Exception....' 
     SET @output = CAST(@message AS text) -- send message to c#/.net 
     RAISERROR(@message,0,1) WITH NOWAIT -- send message to SQL Server Management Studio 
    ... 
end 
go 

다음은 C#/EF 측 :

SQL 서버 예외 레벨 1 ~ 10에서
public string CallMyStoredProcedure(string input) 
{ 
    var outputParameter = new ObjectParameter("output", typeof(string)); 
    EntityContext.MyStoredProcedure(input, outputParameter); 
    return (string)outputParameter.Value; 
} 
3

은 정보 제공 및 후면에 오류가 발생하지 않습니다 너의 어플리케이션.

변경 레벨을 11에서 16 사이로 변경하면 SP에서 오류가 발생합니다.

관련 문제