SQL Server 2014:无法使用bcp和格式文件将任何数据导入LocalDB(零行,无错误)

darth_bloggs

我正在尝试使用非XML bcp格式的文件将数据导入Win7 64位上的LocalDB。最简单的用例。

OS Name:   Microsoft Windows 7 Home Premium
OS Version: 6.1.7601 Service Pack 1 Build 7601
LocalDB version: Microsoft SQL Server 2014 (12.0.2000.8)
BCP version: 12.0.2000.8

基本上是几天前从Microsoft SQL Server 2014网站下载的所有内容的最新版本。

我可以通过bcp连接到LocalDB实例以创建格式文件,但是当尝试使用它重新导入最简单的数据时,生成的格式文件不起作用。无论我做什么,bcp都会加载零行,无提示地失败,并且不会将任何错误信息输出到指定的错误文件。

/* create the table */
use try_db;
create table try(num integer);

/* create the format file based on the table. */
bcp try_db.dbo.TRY format nul -n -T -f TRY.fmt -S (localdb)\default_db

/* above command creates a file TRY.fmt with the following contents */
12.0
1
1  SQLINT  1  4  ""  1  num  ""

/* then I create a file data.txt, with just the number 99 in it, followed by a Windows line terminator (\r\n) */

/* then try importing the file into the table */
bcp try_db.dbo.TRY in data.txt -f TRY.fmt -T -S (localdb)\default_db -e errors.txt

结果:

Starting copy...
0 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 1

没有任何内容写入errors.txt。我只是无法让bcp使用格式文件完全导入任何内容!

我还没有尝试使用SQL Server本身(仅使用LocalDB),但是对于像这样简单的东西并不重要。

我尝试如下编辑TRY.fmt文件行:

1  SQLINT  1  4  "\r\n"  1  num  ""

但这也无济于事。

我能够使用-c而不是-f成功导入它:

bcp try_db.dbo.TRY in data.txt -c -T -S (localdb)\default_db -e errors.txt

关于(a)为什么不使用格式文件导入bcp,以及(b)为什么不将错误不打印到指定的错误文件的任何想法?一定有一些非常简单的事情,我在这里弄错了。

请不要建议使用大容量插入或SSIS(等)代替。bcp应该按文档所述工作!

哥们

格式文件描述的是源数据,而不是目标。使用-cdatafiletype='char'输入数据类型时,必须为SQLCHAR。本机数据类型仅在使用-n时有效datafiletype='native'本机格式的源文件始终是二进制文件,因此bcp需要知道每个字段的数据类型,才能读取正确数量的字节并正确解释它们。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章