.net 无法使用TVF结果更新表
我有一个复杂的CLR函数,它返回一行。我可以使用交叉应用来选择结果,这很好,但更新或插入失败。select始终有效,但是insert、select into和update失败,出现以下错误,此错误不会显示在select查询中.net 无法使用TVF结果更新表,.net,sql-server,sql-server-2014,sqlclr,.net,Sql Server,Sql Server 2014,Sqlclr,我有一个复杂的CLR函数,它返回一行。我可以使用交叉应用来选择结果,这很好,但更新或插入失败。select始终有效,但是insert、select into和update失败,出现以下错误,此错误不会显示在select查询中 Msg 6522, Level 16, State 1, Line 1 A .NET Framework error occurred during execution of user-defined routine or aggregate "AppendCLR": S
Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "AppendCLR":
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ArgumentOutOfRangeException:
at System.Collections.ArrayList.get_Item(Int32 index)
at AppendCLR.ProcessData(String EnrollmentID,String InstituteCode)
at AppendCLR.UserDefinedFunctions(SqlString EnrollmentID,SqlString InstituteCode)
.
The statement has been terminated.
TestCLR
是我需要用CLR函数AppendCLR
的结果更新的表#TestCLR_TEMP
和@TestCLR_TEMP
分别是TEMP和table变量
这不起作用:
update a set
a.ID=b.ID,
a.Branch=b.Branch,
a.CourseID=b.CourseID,
a.EnrolDate=b.EnrolDate,
a.CourseTag=b.CourseTag,
a.Micro=b.Micro,
a.StudentTag=b.StudentTag FROM TestCLR a cross apply
dbo.AppendCLR([EnrollmentID],[InstituteCode]) b
这也不行:
select * into #TestCLR_TEMP from dbo.AppendCLR([EnrollmentID],[InstituteCode])
或
然而,这是可行的:
declare table @TestCLR_TEMP (ID bigint,
Branch varchar(100),
CourseID bigint,
EnrolDate DateTime,
CourseTag varchar(100),
Micro varchar(100),
StudentTag varchar(100))
insert into @TestCLR_TEMP select
a.ID,
b.Branch,
b.CourseID,
b.EnrolDate,
b.CourseTag,
b.Micro,
b.StudentTag FROM TestCLR a cross apply
dbo.AppendCLR([EnrollmentID],[InstituteCode]) b
--I have now my results in @TestCLR_TEMP, I can perform an inner join to append these results back to my original table TestCLR
这始终有效:
Select * from dbo.AppendCLR(123,456)
基本上,当我在真实的表上尝试时,所有的插入更新都失败了。SSMS中的错误没有说明任何重要的内容,但如果需要,我可以发布它。
谢谢 我觉得有点愚蠢,但最初的错误是另一个会话在将select查询的结果读入
数据表时使用了事务上下文,而我在读取此空数据表时得到了系统.ArgumentOutOfRangeException
修复程序在连接字符串中使用了inclist=false
我知道我应该关注错误报告,但感谢各位的努力。有时我们会忽略错误消息中的重要细节。请始终发布错误消息。如果没有什么真正的帮助,那么就不会造成伤害。事实上,是的,请发布错误消息。另外,TestCLR
是一个表还是另一个TVF?SQL Server的哪个版本?是否进行了一些更新,请检查,谢谢。另外,我假设[EnrollmentID]
和[InstituteCode]
是TestCLR
表中的字段?我想一旦你开始工作,你会重新命名所有这些对象,对吗?因为“TestCLR”和“AppendCLR”是没有意义的名称,将来只会导致维护问题。
Select * from dbo.AppendCLR(123,456)