1

我写这篇文章的批量插入格式文件:
批量插入格式文件错误

8.0 
7 
1  SQLCHAR  1  9  " "  1  f1   SQL_Latin1_General_CP1_CI_AS 
2  SQLCHAR  1  5  "   "  2  f2  SQL_Latin1_General_CP1_CI_AS 
3  SQLCHAR  1  12  " "  3  f3   SQL_Latin1_General_CP1_CI_AS 
4  SQLCHAR  1  10  " "  4  f4   SQL_Latin1_General_CP1_CI_AS 
5  SQLCHAR  1  8  " " 5  f5   SQL_Latin1_General_CP1_CI_AS 
6  SQLCHAR  1  5  " " 6  f6   SQL_Latin1_General_CP1_CI_AS 
7  SQLCHAR  1  5  "\n" 7  f7   SQL_Latin1_General_CP1_CI_AS 

和我的文件中的数据是:

43266200 6827   43295200 1393/05/23 14:26:26  18  1 
43266200 6819   43295200 1393/05/23 14:28:45 113  1 

但是当我运行此查询:

bulk insert goy 
from 'd:\test.txt' 
with(
    formatfile='d:\format.fmt' 
); 

sql服务器错误是:

Msg 4862, Level 16, State 1, Line 1 
Cannot bulk load because the file "d:\format.fmt" is incomplete or could not be read. Operating system error code (null). 

我该如何解决这个问题?

+0

检查这个答案 - http://stackoverflow.com/a/8270755/1080354 – gotqn 2014-11-02 09:53:41

+1

你的数据显示七列,但你的格式文件只定义六。这可能意味着“文件”d:\ format.fmt“不完整” – 2014-11-02 12:00:43

回答

3

在fmt文件的末尾添加一个新行。然后保存。它会工作