BCP sqlcmd Bulkinsert Unicode issue, unexpected EOF encountered in BCP Data-file

Source: Internet
Author: User
Tags bulk insert

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

    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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.