使用向导导入CSV数据到SQL Server - 神秘的错误消息

问题描述:

我正尝试使用SQL Server导入向导将平面文本文件导入SQL Server。使用向导导入CSV数据到SQL Server - 神秘的错误消息

似乎这样应该很简单。该文本文件是制表符分隔的,没有什么不寻常的。

当我在向导中预览数据时,一切看起来都不错。我已经检查了列映射,所有的数据线,数据类型都看起来不错。

但是当我运行它,这里的错误消息我得到:

Copying to [dbo].[my_table] (Error) Messages 

Error 0xc0202009: Data Flow Task: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. 
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "Invalid character value for cast specification". 
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "Invalid character value for cast specification". 
(SQL Server Import and Export Wizard) 

Error 0xc020901c: Data Flow Task: There was an error with input column "touch4_date" (260) on input "Destination Input" (179). The column status returned was: "The value could not be converted because of a potential loss of data.". 
(SQL Server Import and Export Wizard) 

Error 0xc0209029: Data Flow Task: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "input "Destination Input" (179)" failed because error code 0xC0209077 occurred, and the error row disposition on "input "Destination Input" (179)" 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. 
(SQL Server Import and Export Wizard) 

Error 0xc0047022: Data Flow Task: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Destination - cm_campaigns" (166) failed with error code 0xC0209029. 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. 
(SQL Server Import and Export Wizard) 

Error 0xc0047021: Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread0" has exited with error code 0xC0209029. There may be error messages posted before this with more information on why the thread has exited. 
(SQL Server Import and Export Wizard) 

一些额外的细节....

平面文件只有22行。

在这似乎是造成问题的原因(“touch4_date”)列 - 行19包含空值,和三个包含下列值:

7/2/2008 
8/25/2008 
3/12/2009 

列数据库是日期时间,它允许空值。

其中一个奇怪的方面是平面文件包含其他列的数据格式为“mm/dd/yyyy”,映射到日期时间列,但这些似乎不会导致任何错误?

任何人都可以解决这个问题?

非常感谢提前!

touch4_date列的值不能转换为表列类型。

+0

大卫 - 非常感谢您的回复!该列中只有三个值:“2008年7月2日”,“2008年8月25日”,“3/12/2009”(其他19行不包含任何值)。数据库中的列是日期时间,它被设置为允许空值。这是问题的原因吗? IOW - 这种格式的日期 - “mm/dd/yyyy”不能转换为日期时间? – mattstuehler 2009-09-22 03:59:35

+0

此CSV文件中是否有标题? – 2009-09-22 11:13:47

+0

...和Matt,尝试删除您提到的空行。如果操作在此之后成功,那么至少有一个原因说明为什么此导入不适合您。 – 2009-09-22 12:16:08

尝试将平文文件导入临时表中,其中列tough4_date作为varchar。然后插入到您的实际表中,但使用case语句。

declare @string varchar(50) 

set @string='' 



select 
    case @string 
     when '' then null 
     else @string 
    end as String