状況:
データ テーブルを作成し、TVP パラメーターを使用して SQL ストアド プロシージャを呼び出そうとする 1 つの Clr ストアド プロシージャ。
コード:
public class tvp_test : System.Data.DataTable
{
public tvp_test()
{
this.Column.Add("field1",typeof(System.Int32));
this.Column.Add("field2",typeof(System.Int32));
}
}
.............................................................
{
var tvp = new tvp_test();
.............................................................
using(SqlConnection con = new SqlConnection("context connection=true"))
{
con.Open();
var command = con.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandTest = "prc_test";
command.Parameters.Add("@a",System.Data.SqlDbType.Structured);
command.Parameters["@a"].Value = tvp;
command.ExecuteNonQuery();
con.Close();
}
}
................................................................... ...................................
create procedure prc_test
@a tvp_test readonly
begin
insert into #tmp (field1,field2) /* #tmp is created before the call of the CLR SP */
select field1,field2 from @a
end
問題:
動作が不安定です。一度動作すると、x (x はランダム) が呼び出された後、y (y はランダム) に「重大なエラーが発生しました」という詳細が表示され、その後、サイクルが再び開始されます。エラーが発生し始めると、エラーが同じままであるため、SQL SPが変更され、障害が発生する可能性があるため、問題はCLR SP側にあります。CLR SP と TVP の間に愛着がないのかもしれませんが、それに関する言及は見つかりませんでした。
補足として、動作する場合は長時間動作する可能性がありますが、SP プランを削除すると、障害が発生し始めます。(その「トリガー」にもロジックが見つかりません)
何かご意見は ?前もって感謝します。