简体   繁体   中英

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. Result is (0 row(s) affected) .

I get the following error:

Msg 4820, Level 16, State 1, Line 1
Cannot bulk load. Unknown version of format file "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:

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

file.fmt , empty row at the bottom:

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 [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

I ran into this issue when I installed the latest SSMS on my desktop and ran a bcp export script. I got the exact same error as you. My format file had 14.0 and my SQL Server database was 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. You may want to add -V120 to your bcp export.

  1. Rename the format file from .FMT to .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:

The format file is basically just a file that pass a few information to SQL, no matter the extension.

I'm still not sure why this always works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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