BCP:导入数据并保留标识值会导致"Invalid character value for cast specification"



在将SQL Server 2012的数据复制到Azure DB时,我有问题。在这里,我正在列出我所做的步骤。

  1. 创建.dat.xml格式文件如下:

    bcp.exe dbo.user_sayti out "c:\dbo.user_sayti.dat" -w -k -Slocalhost -dsource_db -Uuser -Ppwd

    bcp.exe dbo.user_sayti format nul -f "c:\dbo.user_sayti.xml" -w -x -Slocalhost -dsource_db -Uuser -Ppwd

    dbo.user_sayti.dat
    dbo.user_sayti.xml

  2. 试图以保持身份值的身份值将其复制到Azure DB:

    bcp.exe dbo.user_sayti in "c:\dbo.user_sayti.dat" -E -f "c:\dbo.user_sayti.xml" -Sserver.database.windows.net -dtarget_db -Uuser -Ppwd

    并有" Invalid character value for cast specification" 错误。
    我不明白为什么,因为.dat文件包含标识列id (PK, int, not NULL)的值127,并且值数量与行数匹配。

  3. 然后,我尝试了没有-E的同一命令,并且该过程成功完成(该特定表中唯一的一行,它出现在target_db中,具有身份列值= 1)。

    <</p>

-w替换-f参数(架构定义)解决了愚蠢的问题:)

相关内容

最新更新