bcp sqlcmd bulkinsert中unicode问题,Unexpected EOF encountered in BCP data-file
senario
进入sqlcmd用:out xxx生成数据文件,由于sqlcmd export to file 默认情况下中文乱码,故用-u(unicode)开关
@echo off & setLocal EnableDelayedExpansion :start @SET DB=AdventureWorks2012 sqlcmd -d%DB% -b -iscript.sql -v pa="out.txt" pwd="%cd%" -W -h-1 TIMEOUT 3 sqlcmd -d%DB% -b -iout.txt -W -h-1 -s^| -u--<strong><strong>由于sqlcmd export to file 默认情况下中文乱码,故用-u(unicode)开关</strong></strong> pause GOTO start到此,中文正常显示
SQLCMD ERROR
Starting copy... SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Server Native Client 11.0]Unexpected EOF encountered in BCP data-file 0 rows copied. Network packet size (bytes): 4096 Clock Time (ms.) Total : 1
原因 datafile in Unicode format 用-c开关导入数据会出错
查看
打开-w开关,导入成功
小结
用bcp in or out data时
- ANSI --> -c
- UNICODE-->-w
Using BULK INSERT to Bulk Import Unicode Character Data
USE AdventureWorks2012; GO BULK INSERT myTestUniCharData FROM 'C:\myTestUniCharData-w.Dat' WITH ( DATAFILETYPE='widechar', --unicoode FIELDTERMINATOR=',' ); GO SELECT Col1,Col2,Col3 FROM myTestUniCharData; GO
参考:
- UNICODE与ANSI的区别【转】
- http://www.cnblogs.com/Pickuper/articles/2050427.html
- Use Unicode Character Format to Import or Export Data (SQL Server)
- https://msdn.microsoft.com/en-us/library/ms188289.aspx
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。