2009-09-22 108 views
1

我正嘗試使用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」,映射到日期時間列,但這些似乎不會導致任何錯誤?

任何人都可以解決這個問題?

非常感謝提前!

回答

1

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

0

嘗試將平文文件導入臨時表中,其中列tough4_date作爲varchar。然後插入到您的實際表中,但使用case語句。

declare @string varchar(50) 

set @string='' 



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