Sql-server – BCP woes: Unexpected EOF encountered in BCP data-file

bcpbulk-insertsql server

I have a table defined as such:

CREATE TABLE [dbo].[IpMetadata](
    [StartIp] [bigint] NOT NULL,
    [EndIp] [bigint] NOT NULL,
    [CountryCode] [char](10) NOT NULL,
    [ProxyType] [varchar](50) NULL,
    [ProxyDescription] [varchar](50) NULL,
    [IspName] [varchar](100) NULL,
    [MobileCarrier] [varchar](50) NULL,
    [MobileCarrierCode] [varchar](50) NULL,
    [Latitude] [varchar](50) NULL,
    [Longitude] [varchar](50) NULL,
    [PostalCode] [varchar](50) NULL,
    [City] [varchar](50) NULL,
    [Region] [varchar](50) NULL,
    [Country] [varchar](50) NULL,
    [GmtOffset] [varchar](50) NULL,
    [SupportsDaylightSavings] [char](10) NULL,
    [MetroCode] [varchar](50) NULL,
    [AddressCount] [int] NOT NULL,
     CONSTRAINT [PK_IpMetadata] PRIMARY KEY CLUSTERED 
    (
        [StartIp] ASC,
        [EndIp] ASC
    )
)

I have a UTF-8 encoded sampling file (D:\data\ipsnip.csv) with tab-delimited, CRLF terminated rows to insert into this table like so:

#start-ip   end-ip  edge-two-letter-country proxy-type  proxy-description   isp-name    mobile-carrier  mobile-carrier-code edge-latitude   edge-longitude  edge-postal-code    edge-city   edge-region edge-country    edge-gmt-offset edge-in-dst edge-metro-code address-count
0   0   **                  0   0   0   0   reserved    *** *** +9999   n   -1  0
1   255 **                  0   0   0   0   reserved    *** *** +9999   n   -1  254
256 16777215    **                  0   0   0   0   reserved    *** *** +9999   n   -1  16776959
16777216    16777343    au                  0   -37.7596    145.134 3106    templestowe vic aus +1000   n   36211   127
16777344    16777407    au                  0   -37.7596    145.134 3106    templestowe vic aus +1000   n   36211   63
16777408    16777471    au                  0   -37.7596    145.134 3106    templestowe vic aus +1000   n   36211   63
16777472    16778239    cn          chinanet fujian province network        0   26.0786 119.298 350000  fuzhou  35  chn +800    n   156115  767
16778240    16779263    au          big red group       0   -37.8387    144.99  3141    south yarra vic aus +1000   n   36206   1023
16779264    16781311    cn          chinanet guangdong province network     0   30.6611 104.082 510000  guangzhou   44  chn +800    n   156196  2047
16781312    16785407    jp          i2ts inc.       0   35.6838 139.754 100-0001    tokyo   13  jpn +900    n   -1  4095

I run the BCP command like so:

bcp MyDatabase.dbo.IpMetadata in D:\data\ipsnip.csv -F2 -Slocalhost -n -T

I get a response back like so:

Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 11 for SQL Server]Unexpected EOF encountered in BCP data-file

BCP copy in failed

I have tried explicitly specifying the column and row terminators. I have tried using unicode column definitions. I have tried changing the line ends to LF instead of CRLF. I have tried replacing the field terminators with semicolons/ pipes. I have tried -n and-N. I don't know what else to try. Can anyone assist?

Best Answer

So it turns out that the -n and the -N are not what I wanted; I had assumed it used the db metadata to implicitly convert the incoming data, but it looks like it's expecting binary data with that.

I changed it to -c and it worked without issue.