最近在把一个大的文本文件中的数据导入到sql2005中时,出现错误。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

相同文件导入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等文本编辑工具可以处理大文本。