[英]`bcp in` fails with "INSERT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'"
I exported a table (created with EF Core 2.2) with bcp %database%.MyTable out MyTable.dmp -n -T -S %sqlserver%
.我使用
bcp %database%.MyTable out MyTable.dmp -n -T -S %sqlserver%
导出了一个表(使用 EF Core 2.2 创建)。
On reimporting it with bcp %database%.MyTable in MyTable.dmp -n -T -S %sqlserver%
I get this error:在使用
bcp %database%.MyTable in MyTable.dmp -n -T -S %sqlserver%
重新导入它时,我收到此错误:
SQLState = 37000, NativeError = 1934
Error = [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]INSERT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.
The table is created with QUOTED_IDENTIFIER = ON
and does not contain any computed column :该表是使用
QUOTED_IDENTIFIER = ON
创建的,不包含任何计算列:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [MyTable](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[OwnerLoginId] [bigint] NOT NULL,
[RowVersion] [timestamp] NULL,
[CreatedAt] [datetime2](7) NOT NULL,
[DataId] [bigint] NOT NULL,
[SomeString] [nvarchar](30) NOT NULL,
[AnotherString] [nvarchar](30) NULL,
CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [MyTable] WITH CHECK ADD CONSTRAINT [FK_MyTable_SomeOtherTable_DataId_SomeString] FOREIGN KEY([DataId], [SomeString])
REFERENCES [SomeOtherTable] ([DataId], [SomeString])
GO
ALTER TABLE [MyTable] CHECK CONSTRAINT [FK_MyTable_SomeOtherTable_DataId_SomeString]
GO
ALTER TABLE [MyTable] WITH CHECK ADD CONSTRAINT [FK_MyTable_DataTable_DataId] FOREIGN KEY([DataId])
REFERENCES [DataTable] ([Id])
GO
ALTER TABLE [MyTable] CHECK CONSTRAINT [FK_MyTable_DataTable_DataId]
GO
The BCP utility connects with QUOTED_IDENTIFIER OFF
for backwards compatibility. BCP 实用程序与
QUOTED_IDENTIFIER OFF
连接以实现向后兼容性。 You'll need to add the -q
option to use QUOTED_IDENTIFIER ON
.您需要添加
-q
选项以使用QUOTED_IDENTIFIER ON
。
The BCP documentation instructs the entire qualified table name be enclosed in quotes when the -q
option is specified. BCP 文档指示在指定
-q
选项时将整个限定表名称括在引号中。 However, this does not work when the database name doesn't conform to regular identifier naming rules .但是,当数据库名称不符合常规标识符命名规则时,这不起作用。 The period in the database name is the culprit here.
数据库名称中的句点是这里的罪魁祸首。
A workaround is to specify a 2-part table name and specify the database name separately using the -d
option:一种解决方法是指定一个由 2 部分组成的表名并使用
-d
选项单独指定数据库名:
bcp "MySchema.MyTable" in "MyTable.dmp" -q -n -T -S "(localdb)\MSSQLLocalDB" -d "My.Database"
IMHO, it is best to name objects according to the rules for regular identifiers to avoid the need to enclose the names and jumping through hoops like this.恕我直言,最好根据常规标识符的规则命名对象,以避免需要将名称括起来并像这样跳过箍。
The error message suggests you are using other features besides indexes on computed columns that require QUOTED_IDENTIFIER ON
.该错误消息表明您正在使用除需要
QUOTED_IDENTIFIER ON
计算列上的索引之外的其他功能。 These include filtered indexes, indexed views, and XML indexes.其中包括过滤索引、索引视图和 XML 索引。 My guess is a filtered index or indexed view is the culprit here.
我的猜测是过滤索引或索引视图是这里的罪魁祸首。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.