问题
I was trying copy data from a table to another table in another database using bcp.
First a format file was created using
!! bcp dbName1.dbo.tableName1 format nul -S serverName1 -T -f D:\tableName1_fmt.txt -n
Then the data file was created using
!! bcp dbName1.dbo.tableName1 out D:\tableName1.txt -S serverName1 -T -c
Now I tried to import the data-file to another table in another database present in another server using the format file
!! bcp dbName2.dbo.tableName2 in D:\tableName1.txt -f D:\tableName1_fmt.txt -S ServerName2 -T -E
Then the following error was generated
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]Unexpected EOF encountered in BCP data-file
0 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 1
I figured out the problem. But it was a different case from the existing ones in Stackoverflow.
So I am writing my solution in case someone encounter with the same may benefit.
回答1:
The problem was with format specifiers (-c
, -n
) while creating Format-file and Data-file.
The format specifier for Format File (-n
) and Data File (-c
) was different.
When I changed format specifier of both to either -c
or -n
, the import statement worked.
Since retaining datatype of columns was important for my purpose, -n
was used for format file and data file
来源:https://stackoverflow.com/questions/52295174/unexpected-eof-encountered-in-bcp-data-file