批量插入格式文件错误

时间:2014-11-02 05:39:52

标签: sql sql-server sql-server-2008 sql-server-2008-r2 sql-server-2012

我写这个批量插入格式文件:

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 server错误是:

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).

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

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