问题描述
我正在对 sqlserver 执行 BULK INSERT,但它没有正确地将 UTF-8 字符插入到数据库中.数据文件中包含这些字符,但批量插入执行后数据库行包含垃圾字符.
I am doing a BULK INSERT into sqlserver and it is not inserting UTF-8 characters into database properly. The data file contains these characters, but the database rows contain garbage characters after bulk insert execution.
我的第一个怀疑是格式文件的最后一行:
My first suspect was the last line of the format file:
10.0
3
1 SQLCHAR 0 0 "{|}" 1 INSTANCEID ""
2 SQLCHAR 0 0 "{|}" 2 PROPERTYID ""
3 SQLCHAR 0 0 "[|]" 3 CONTENTTEXT "SQL_Latin1_General_CP1_CI_AS"
但是,在阅读这个之后官方页面 在我看来,这实际上是 SQL Server 2008 版中插入操作读取数据文件的错误.我们使用的是 2008 R2 版.
But, after reading this official page it seems to me that this is actually a bug in reading the data file by the insert operation in SQL Server version 2008. We are using version 2008 R2.
此问题的解决方案或至少是解决方法是什么?
What is the solution to this problem or at least a workaround?
推荐答案
你不能.您应该首先使用 N 类型数据字段,将您的文件转换为 UTF-16,然后将其导入.数据库不支持UTF-8.
You can't. You should first use a N type data field, convert your file to UTF-16 and then import it. The database does not support UTF-8.
这篇关于如何在 SQL Server 中使用批量插入编写 UTF-8 字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!