使用表值参数从 CLR 存储过程中调用存储过程
情况:
一个 Clr 存储过程构建数据表,然后尝试使用 TVP 参数调用 SQL 存储过程。
代码:
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 是随机的)“发生严重错误”,没有其他详细信息,之后循环将再次开始。从我看来,问题出在 CLR SP 方面,因为当错误开始发生时,SQL SP 可能会发生更改并出现错误,因为错误保持不变。 也许CLR SP和TVP之间没有爱,但我没有找到任何相关的参考资料。
顺便说一句,当它工作时,它可能会工作很长时间,但如果我删除 SP 计划,那么它就会开始出现故障。 (也找不到该“触发器”中的逻辑)
有什么想法吗? 先感谢您。
The situation:
One Clr stored procedure that builds a data table and then it tries to call an SQL Stored procedure with a TVP parameter.
The code:
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
The problem:
The behavior is erratic. One time it works, after x (where x is random) calls it will give me y (where y is random) "severe error occurred" with no other details, and after that the cycle will start again. From what I see the problem is on the CLR SP side as when errors start to occur, the SQL SP can be changed and be faulty as the error remains the same.
Maybe there is no love between CLR SP and TVPs, but I didn't find any reference to that.
As a side note, when it works it may work for a long time, but if I delete the SPs plan then it will start faulting. (can't find the logic in that "trigger" also)
Any thoughts ?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这一行有错误。
将其更改为
Looks like this line has an error.
Change it to