简体   繁体   English

`bcp in` 失败并显示“插入失败,因为以下 SET 选项设置不正确:'QUOTED_IDENTIFIER'”

[英]`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.

相关问题 SQL Server:INSERT / UPDATE / DELETE失败,因为以下SET选项具有错误的设置:'QUOTED_IDENTIFIER' - SQL Server: INSERT/UPDATE/DELETE failed because the following SET options have incorrect settings: ‘QUOTED_IDENTIFIER’ INSERT 失败,因为以下 SET 选项的设置不正确:'QUOTED_IDENTIFIER' - INSERT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER' SQL 查询通知 - 更新失败,因为以下 SET 选项的设置不正确:'QUOTED_IDENTIFIER' - SQL Query Notifications - UPDATE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER' Docker CREATE INDEX中的SQL Server失败,因为以下SET选项的设置不正确:'QUOTED_IDENTIFIER' - SQL Server in Docker CREATE INDEX failed because the following SET options have incorrect settings: ‘QUOTED_IDENTIFIER’ 删除所有表时出错“DELETE 失败,因为以下 SET 选项的设置不正确:'QUOTED_IDENTIFIER'” - Error deleting all tables "DELETE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'" INSERT失败,因为以下SET选项的设置不正确:“ ARITHABORT”。 - INSERT failed because the following SET options have incorrect settings: 'ARITHABORT'. UPDATE失败,因为以下SET选项的设置不正确:'ARITHABORT' - UPDATE failed because the following SET options have incorrect settings: 'ARITHABORT' 由于以下SET选项的设置不正确,导致由于INSERT而出错 - Getting Error as INSERT failed because the following SET options have incorrect settings INSERT失败,因为以下SET选项具有错误的设置:'CONCAT_NULL_YIELDS_NULL' - INSERT failed because the following SET options have incorrect settings: 'CONCAT_NULL_YIELDS_NULL' 过滤的唯一索引导致更新由于错误的“ QUOTED_IDENTIFIER”设置而失败 - Filtered Unique Index causing UPDATE to fail because incorrect 'QUOTED_IDENTIFIER' settings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM