You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用SSIS向SQL Server导入CSV数据失败求助

SSIS导入CSV至SQL Server日期转换失败的解决方案

问题背景

使用SSIS导入本地CSV到SQL Server,已通过以下SQL创建目标表:

use sample_superstore

drop table dbo.orders;

create table dbo.orders
(
    "Order_ID" varchar(50),
    "Order_Date" date null,
    "Ship_Date" date null,
    "Ship_Mode" varchar(50),
    "Customer_ID" varchar(50),
    "Country" varchar(50),
    "City" varchar(50),
    "Product_ID" varchar(50),
    "Category" varchar(50),
    "Sub-Category" varchar(50),
    "Product_Name" nvarchar(150)
);

select * from dbo.orders;

导入时触发以下错误:

Error: 0xC020901C at Upload Data, OLE DB Destination [62]: There was an error with OLE DB Destination.Inputs[OLE DB Destination Input].Columns[Order Date] on OLE DB Destination.Inputs[OLE DB Destination Input].

The column status returned was: "The value could not be converted because of a potential loss of data."
Error: 0xC0209029 at Upload Data, OLE DB Destination [62]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "OLE DB Destination.Inputs[OLE DB Destination Input]" failed because error code 0xC0209077 occurred, and the error row disposition on "OLE DB Destination.Inputs[OLE DB Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
Error: 0xC0047022 at Upload Data, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "OLE DB Destination" (62) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (75). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.

尝试将数据类型改为DT_DATE后问题仍存在。

解决步骤

1. 修正Flat File Source的日期解析配置

  • 打开Flat File Source的高级编辑器,切换到「输入和输出属性」选项卡
  • 找到Order Date和Ship Date列,修改以下属性:
    • 将LocaleID设置为匹配CSV日期格式的区域(例如:中文区域用2052,英式日期用2057)
    • 若日期格式固定,直接设置Format属性为对应的格式字符串(如dd/MM/yyyy或MM/dd/yyyy)
    • 确认数据类型设置为DT_DBDATE(而非DT_DATE,DT_DBDATE与SQL Server的date类型完全匹配)

2. 添加显式数据转换组件

避免依赖SSIS自动转换,手动添加转换逻辑:

  • 在数据流任务中拖入「数据转换」组件,连接Flat File Source与该组件
  • 打开数据转换编辑器,选择Order Date和Ship Date列,将转换后的数据类型设置为DT_DBDATE
  • 将转换组件的输出连接到OLE DB Destination,确保转换后的列与目标表的Order_Date、Ship_Date正确映射

3. 排查CSV中的异常数据

  • 检查CSV文件中是否存在无效日期值(如N/A、00/00/0000、超出日期范围的数值,或格式混乱的字符串)
  • 在Flat File Source的错误输出设置中,将错误行重定向到单独的文件,导出后逐一修正异常数据

4. 验证列映射与表结构

  • 确认OLE DB Destination的列映射中,Order Date(CSV列)正确对应到目标表的Order_Date列,避免因列名空格/下划线差异导致映射错误
  • 检查目标表的date列是否存在额外约束(如检查约束限制日期范围),如有则调整约束或修正数据

内容的提问来源于stack exchange,提问作者Shash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 03:46:16