I am calling a T-SQL stored procedure from a CLR stored procedure. and the THROW statement in T-SQL stops the execution of CLR without going into the catch block. Is there something I can change in my code to cause the CLR procedure to execution the catch block?
T-SQL:
CREATE TABLE t1 (ID INT PRIMARY KEY clustered);
CREATE TABLE t2 (ID INT CONSTRAINT fk_1 FOREIGN KEY REFERENCES t1(ID))
GO
CREATE PROC dbo.TestThrow
AS
BEGIN
BEGIN TRY
INSERT INTO t2 VALUES (1)
END TRY
BEGIN CATCH
THROW
END CATCH
END
GO
CLR:
public static void TestThrow()
{
String query = "EXEC DBO.TESTTHROW";
using (SqlConnection connection = new SqlConnection("context connection=true"))
{
connection.Open();
try
{
using (SqlCommand command = new SqlCommand(query, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
SqlContext.Pipe.Send("no error");
}
}
}
catch (SqlException e)
{
SqlContext.Pipe.Send("sqlexception");
SqlContext.Pipe.Send(e.Message);
}
catch (Exception e)
{
SqlContext.Pipe.Send("exception");
SqlContext.Pipe.Send(e.Message);
}
}
}