Senario
Enter sqlcmd with: Out XXX generate Data file, because sqlcmd export to file by default Chinese garbled, so with the-u (Unicode) switch
@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> Because sqlcmd export to file is garbled by default in Chinese, the-u (Unicode) switch </strong></strong>pausegoto start
To this, Chinese normal display
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
Cause datafile in Unicode format imports data with the-C switch error
View
Open the-w switch for successful import
Summary
When using bcp in or out data
- ANSI-C
- 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
Reference:
- The difference between Unicode and ANSI "Go"
- 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
BCP sqlcmd Bulkinsert Unicode issue, unexpected EOF encountered in BCP Data-file