bcp sqlcmd bulkinsert中unicode問題,Unexpected EOF encountered in BCP data-file,sqlcmdbulkinsert
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時
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