简体   繁体   English

SQL Server批量插入 - “无法批量加载。 格式文件的未知版本“

[英]SQL Server bulk insert - “Cannot bulk load. Unknown version of format file”

Update: I was using version 12.0.2269.0 of SQL Server but BCP generated a script for version 13. Changing this and got rid of the error but the command is not working anyway. 更新:我使用的是SQL Server 12.0.2269.0版,但是BCP为版本13生成了一个脚本。更改了这个并删除了错误,但命令无论如何都无法正常工作。 Result is (0 row(s) affected) . 结果是(0 row(s) affected)

I get the following error: 我收到以下错误:

Msg 4820, Level 16, State 1, Line 1 Msg 4820,Level 16,State 1,Line 1
Cannot bulk load. 无法批量加载。 Unknown version of format file "file.fmt". 格式文件“file.fmt”的未知版本。

From this bulk insert command: 从这个批量插入命令:

BULK INSERT Hello
FROM 'C:\data.csv'
WITH (
    FORMATFILE='C:\file.fmt'
)

To generate the .fmt file I followed this guide: 要生成.fmt文件,我按照本指南操作:

https://msdn.microsoft.com/en-us/library/ms191516.aspx https://msdn.microsoft.com/en-us/library/ms191516.aspx

file.fmt , empty row at the bottom: file.fmt ,底部为空行:

13.0
20
1       SQLCHAR             0       11      "\t"     1     person_nr                                  Finnish_Swedish_CI_AS
2       SQLCHAR             0       50      "\t"     2     fornamn                                    Finnish_Swedish_CI_AS
3       SQLCHAR             0       50      "\t"     3     efternamn                                  Finnish_Swedish_CI_AS
4       SQLCHAR             0       50      "\t"     4     adress                                     Finnish_Swedish_CI_AS
5       SQLCHAR             0       50      "\t"     5     co_adress                                  Finnish_Swedish_CI_AS
6       SQLCHAR             0       10      "\t"     6     postnr                                     Finnish_Swedish_CI_AS
7       SQLCHAR             0       50      "\t"     7     postadress                                 Finnish_Swedish_CI_AS
8       SQLCHAR             0       12      "\t"     8     bevakad                                    ""
9       SQLCHAR             0       41      "\t"     9     limit                                      ""
10      SQLCHAR             0       24      "\t"     10    upplysning_datum                           ""

BCP commands to generate format file: BCP命令生成格式文件:

bcp [Database].[dbo].[Hello] format nul -T -n -f "C:\file.fmt"

bcp [Database].[dbo].[Hello] format nul -c -f "C:\file.fmt" -T

Has anyone else experienced this? 还有其他人经历过这个吗?

Yes, I have experienced this. 是的,我经历过这个。

The simple solution for you is to edit the format file and change 13.0 to 12.0 对您而言,简单的解决方案是编辑格式文件并将13.0更改为12.0

I ran into this issue when I installed the latest SSMS on my desktop and ran a bcp export script. 我在桌面上安装了最新的SSMS并运行了bcp导出脚本时遇到了这个问题。 I got the exact same error as you. 我得到了与你完全相同的错误。 My format file had 14.0 and my SQL Server database was 13.0 (2016). 我的格式文件有14.0,我的SQL Server数据库是13.0(2016)。 Simply editing the version number in the format file resolved the load error for me. 只需编辑格式文件中的版本号即可解决加载错误。

Note: I added the -V130 argument to my bcp command and I don't have this issue anymore. 注意:我在我的bcp命令中添加了-V130参数,我不再有这个问题了。 You may want to add -V120 to your bcp export. 您可能希望将-V120添加到bcp导出中。

  1. Rename the format file from .FMT to .txt . 将格式文件从.FMT重命名为.txt
  2. Add an empty row at the at the end of the file 在文件末尾添加一个空行
  3. Change the file extension from .FMT to .txt in the query and run it: 在查询中将文件扩展名从.FMT更改为.txt并运行它:

The format file is basically just a file that pass a few information to SQL, no matter the extension. 格式文件基本上只是一个将一些信息传递给SQL的文件,无论扩展名如何。

I'm still not sure why this always works. 我仍然不确定为什么这总是有效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM