首页 新闻 会员 周边

关于SSIS 导出csv 的文件的编码格式的问题。

0
悬赏园豆:10 [已解决问题] 解决于 2012-08-20 15:23

我设计了一个SSIS 包体,从MS SQL 2008 导出数据到csv 文件,由于CSV 文件的使用者是外国人,需要吧csv 文件编码改为utf-8 的格式,我在导出时候,使用转换方式,把每行都转换为了string[DT_CY] 数据类型,code page 使用65001(utf-8) , flat file destination 的 CSV 文件编码也是有utf-8 ,但是为什么包体执行后,生成的 CSV 文件的默认的编码改为了ANSI 的格式?

那位高手可以指点我一下?

figofeng的主页 figofeng | 初学一级 | 园豆:5
提问于:2012-06-27 14:39
< >
分享
最佳答案
0

参考这个帖子中的解决方法:Export SQL View to Flat File with UTF-8 Encoding

收获园豆:10
dudu | 高人七级 |园豆:31007 | 2012-06-27 16:10

按照帖子方法,去掉了“Overwrite data in the file” 的选项了,可是还是生成ansi 编码的csv 文件。

figofeng | 园豆:5 (初学一级) | 2012-06-27 17:02

专家,能详细告诉我一下吗?

figofeng | 园豆:5 (初学一级) | 2012-06-28 09:19

@figofeng: 在Flat File Destination设置窗口,Locale选择的是什么?

dudu | 园豆:31007 (高人七级) | 2012-06-28 10:10

@dudu: chinese (people's republic of china)

figofeng | 园豆:5 (初学一级) | 2012-06-28 10:34

@figofeng: 在SQL Server Management Studio中手工进行导出会出现这个问题吗?

dudu | 园豆:31007 (高人七级) | 2012-06-28 10:37

@dudu: 手动导出,不会改变编码方式,还是UTF8 没有变成ansi

figofeng | 园豆:5 (初学一级) | 2012-06-28 10:49

@figofeng: SQL官方论坛提到了这个问题——

Export SQL View to Flat File with UTF-8 Encoding

一楼的回答:

You are right, guys. It looks like we do not add BOMs to UTF-8 encoded files. We treat it like any other ANSI file encoded using specified code page. The UTF-8 (65001) code page is kind of specific, and we should have probably added the appropriate BOM to such files. Feel free to open a bug for this on the connect site (connect.microsoft.com).

In the meantime, I can think of a workaround where you prepare your files in advance (with a proper BOM in it) and then append data to it by unchecking the "Overwrite data in the file" option in the Flat File Destination editor.

 

问题的原因是:SSIS没将BOM(Byte Order Mark, Unicode签名)写入到导出的文件中。

解决方法:先创建空的同名的UTF-8文件,然后在导出选项中选择取消"Overwrite data in the file"的选择。

dudu | 园豆:31007 (高人七级) | 2012-06-28 11:41

@dudu: 您好,感谢您,我知道原因了,我想在CSV内保留最新的数据,所以,每次都先删除CSV文件,然后系统自己建立一个CSV 文件,这样就没有BOM 信息,我现在在先建立一个CSV文件作为模板,每次在删除源CSV 文件后,拷贝一个模板文件到目标位置,就直接在这个UTF8的文件内增加数据了。感谢您啊。

figofeng | 园豆:5 (初学一级) | 2012-06-28 13:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册