微软BI 之SSIS 系列 - 2008 版本中变量 Int64 无法保存 bigint 类型数据的BUG
2015-01-15 23:54 BIWORK 阅读(2522) 评论(0) 编辑 收藏 举报开篇介绍
这是今天在帮别人看一个 2008R2 版本的项目时发现的一个 Bug,这个 Bug 在 SQL SERVER 2012 有的版本中可能已经解决,但在论坛上看到有的仍然存在。
在 SQL SERVER 2008 R2 版本中,比如从一个数据库表中取一个 BIGINT 类型的数据,赋值给一个 Int64 类型的变量,按照我们的理解肯定是正确的。
但是结果是报错了 -
错误原因:类型不一致造成的。
[Execute SQL Task] Error: An error occurred while assigning a value to variable "MAX_ID": "The type of the value being assigned to variable "User::MAX_ID" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
".
当时也非常的奇怪,觉得这里的配置没有任何问题,怀疑同事机器环境有问题,于是就在我本机 SQL SERVER 2012 的环境下测试了一遍。
同样的逻辑是通过的。
后来到网上查了一下,果然是 SQL SERVER 2008 R2 版本中的一个 BUG,始自 2005,很惭愧,我到现在才发现这是一个 BUG。
Why can’t I store my BIGINT result in an Int64 variable?
The native providers (OLEDB, ODBC, ADO – ADO.NET doesn't have this problem) in the Execute SQL Task return the BIGINT type as a String, and not an Int64 as you'd expect. Attempting to store the result in an Int64 variable gives you an error along the lines of:
[Execute SQL Task] Error: An error occurred while assigning a value to variable "xxxx": "The type of the value being assigned to variable "xxxx" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object."
Although this behavior is documented in the books online entry, we don't explain why it was done this way. Being somewhat new to the SSIS development team, I had to do some digging to find out for myself. It turns out that at the time this was implemented, there wasn't cross platform support for the 8-byte integer type (VT_I8/VT_UI8) in VARIANTs -- specifically, on Windows 2000. Now that supporting Win2k is no longer an issue (for Katmai), we're free to change the behavior (while maintaining backwards compatibility for packages that are expecting the value as a string, of course).
Expect this as a likely change in an upcoming release.
如何解决
SQL SERVER 2012 版本已经纠正过来了,所以用 SQL SERVER 2012 的时候应该没有问题。如果还是使用 SQL SERVER 2008 R2 的话,解决的办法就是将数据类型改为 String,用它来接受 SQL SERVER 中 BIGINT 数据类型的数据。
另外,可能大家会问 - 如何这个变量正好也要写入一个 COLUMN类型为 BIGINT 类型的数据表中怎么办?
这个是没有任何问题的,如果 COLUMN 的类型是数值,日期的话,String 类型会自动发生转换插入的,因此 String 的变量会自动转换为对应的 BIGINT 插入到数据表中。
更多 BI 文章请参看 BI 系列随笔列表 (SSIS, SSRS, SSAS, MDX, SQL Server) 如果觉得这篇文章看了对您有帮助,请帮助推荐,以方便他人在 BIWORK 博客推荐栏中快速看到这些文章。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 单线程的Redis速度为什么快?
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
2014-01-15 微软BI 之SSRS 系列 - 如何实现报表导航 Navigation 和钻取 Drill Down 的效果