问题描述
我试图使用bcp将数据从一个表复制到另一个数据库中的另一个表.
首先使用以下格式创建格式文件
!! bcp dbName1.dbo.tableName1 format nul -S serverName1 -T -f D:\tableName1_fmt.txt -n
然后使用以下文件创建数据文件
!! bcp dbName1.dbo.tableName1 out D:\tableName1.txt -S serverName1 -T -c
现在,我尝试使用格式文件将数据文件导入另一台服务器中另一个数据库中的另一个表中
!! bcp dbName2.dbo.tableName2 in D:\tableName1.txt -f D:\tableName1_fmt.txt -S ServerName2 -T -E
然后产生了以下错误
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
我发现了问题所在.但这与Stackoverflow中的现有情况不同.
因此,如果有人遇到相同的问题可能会受益,那么我正在写我的解决方案.
问题在于创建格式文件和数据文件时使用格式说明符(-c
,-n
)./p>
格式文件(-n
)和数据文件(-c
)的格式说明符不同.
当我将两者的格式说明符都更改为-c
或-n
时,导入语句起作用.
由于保留列的数据类型对我而言很重要,因此-n
用于格式文件和数据文件
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.
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
这篇关于BCP数据文件中遇到意外的EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!