sql2005數據導入出錯問題

最近在把一個大的文本文件中的數據導入到sql2005中時,出現錯誤。

相同文件導入sql2000則不會出現錯誤。

 

網絡上一查,也有部分人碰到這個問題。解決的辦法2005年的時候,就有人貼出來了:

出錯的原因各種各樣,裏面有很多人列舉了自己的問題。

 

主要原因是數據轉換的時候,sql2005中的缺省設置時字符長度爲50。對於有些數據來說,這個太短了,引起字符串被截斷,產生錯誤。因此數據轉換中途停止。解決的辦法如下:

 

The flat file defaults initially all columns to characters with length of 50. You can change this by going to the “Advanced” page of the Flat File connection page and change the length manually, or you can click on "Suggest Types..." to get suggested column metadata attributes based on sampling a certain number of rows from the file.

 

就是在

 

When you enter your data source, you have an advanced tab on the left. After that, click on the offending column and one of the properties under 'Misc' on the right is OutputColumnWidth. Enter the correct value here and your problems will be gone. If you read the description for OutputColumnWidth you will see: "The width of this column in the data flow."

 

通過修改相關列的數據長度,可以解決這個問題。有些人比較誇張,一律把所有數據段的長度改爲8000(好像sql2000中缺省就是8000,這樣儘管不會出錯,但是太浪費空間了。)

 

最有趣的有一個網友這樣感謝提出解決方案的人:

 

Thanks R2 DJ
You have saved what little hair I have left on my head !!
Steve
夠幽默!

 

實際上,如果能夠仔細閱讀出錯信息,同時仔細觀察相關的文本文件的內容,可以很快定位類似問題。當然,如果碰上大文件,用notepad是無法解決問題的,這個時候,用ultraedit等文本編輯工具可以處理大文本。
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章