我正在尝试使用 SSIS 2008 中的执行 SQL 任务将存储过程输出参数映射到包变量。
包变量为SSIS类型DateTime,存储过程参数为SQL类型DATETIME。
SQL 语句是 EXEC GetCurrentDate @CurrentDate=?
并且在参数映射屏幕中,参数映射到指定方向输出和数据类型 DBTIMESTAMP 的包变量。
当我运行包时,出现以下错误:
[Execute SQL Task] Error: Executing the query "EXEC GetCurrentDate @CurrentDate=? " failed with the following error: "The type of the value being assigned to variable "User::CurrentDate" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object. ". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
如果我对正在运行的查询运行跟踪,我会看到类型被假定为 datetime2:
declare @p3 datetime2(7)
set @p3=NULL
exec sp_executesql N'EXEC GetCurrentDate @CurrentDate=@P1 ',N'@P1 datetime2(7) OUTPUT',@p3 output
select @p3
有谁知道为什么假设类型是 datetime2?
谢谢
最佳答案
在 Micorsoft Connect 错误报告中找到答案:
We are closing this case as this is expected behaviour and is a result of the new sql datetime type change. You are using a native oledb connection manager for sql task, in the process of COM interop, we use VARIANT to hold the value and the only way to prevent data loss is to store the value as BSTR variant. If you change User::dateParam to String type it will work, or you can switch to use managed connection manager to bypass the COM interop.
http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=307835
关于sql-server-2008 - SSIS 2008 Execute SQL输出参数映射datetime2问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/876886/