当前位置: 代码迷 >> SQL >> bcp sqlcmd bulkinsert中unicode有关问题,Unexpected EOF encountered in BCP data-file
  详细解决方案

bcp sqlcmd bulkinsert中unicode有关问题,Unexpected EOF encountered in BCP data-file

热度:448   发布时间:2016-05-05 10:41:41.0
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=AdventureWorks2012sqlcmd  -d%DB% -b -iscript.sql -v pa="out.txt" pwd="%cd%" -W -h-1TIMEOUT 3sqlcmd  -d%DB% -b -iout.txt -W -h-1 -s^| -u--<strong><strong>由于sqlcmd export to file 默认情况下中文乱码,故用-u(unicode)开关</strong></strong>pauseGOTO start
到此,中文正常显示

SQLCMD ERROR

Starting copy...SQLState = S1000, NativeError = 0Error = [Microsoft][SQL Server Native Client 11.0]Unexpected EOF encountered in BCP data-file0 rows copied.Network packet size (bytes): 4096Clock Time (ms.) Total     : 1

原因 datafile in Unicode format 用-c开关导入数据会出错


查看


打开-w开关,导入成功


小结

用bcp  in or out data时

  1. ANSI         --> -c
  2. UNICODE-->-w

Using BULK INSERT to Bulk Import Unicode Character Data

USE AdventureWorks2012;GOBULK INSERT myTestUniCharData    FROM 'C:\myTestUniCharData-w.Dat'    WITH (      DATAFILETYPE='widechar', --unicoode      FIELDTERMINATOR=','   ); GOSELECT 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

  相关解决方案