简体   繁体   English

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’

I have a SQL Server Dockerfile with my import-data.sh importing *.sql files from a sql-data folder. 我有一个SQL Server Dockerfile,我的import-data.sh从sql-data文件夹导入*.sql文件。 Everything works if I run the *.sql files from a tool like Datagrip but the import fails with this error message when it's ran automatically. 如果我从Datagrip这样的工具运行*.sql文件,但是当它自动运行时导入失败并显示此错误消息,则一切正常。

Error message: 错误信息:

Msg 1934, Level 16, State 1, Line 4 Ms 1934,Level 16,State 1,Line 4
CREATE INDEX failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. CREATE INDEX失败,因为以下SET选项具有不正确的设置:'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. 验证SET选项是否正确,以便与计算列和/或筛选索引和/或查询通知和/或XML数据类型方法和/或空间索引操作的索引视图和/或索引一起使用。

Dockerfile Dockerfile

FROM microsoft/mssql-server-linux:2017-latest

RUN mkdir /sql-data/
EXPOSE 1433

COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

COPY import-data.sh /usr/src/app/
RUN chmod +x /usr/src/app/import-data.sh

# Copy SQL Scripts to sql-data for processing
COPY ./sql-data/*.sql /sql-data/

CMD /bin/bash /usr/local/bin/entrypoint.sh

entrypoint.sh entrypoint.sh

#!/bin/bash

#start SQL Server, start the script to create the DB and import the data, start the app
/usr/src/app/import-data.sh & /opt/mssql/bin/sqlservr

import-data.sh import-data.sh

#!/bin/bash
# wait for the SQL Server to come up https://github.com/twright-msft/mssql-node-docker-demo-app/issues/11
while [ ! -f /var/opt/mssql/log/errorlog ]
do
  sleep 2
done

## tail the error log for the startup dll and then quit
tail -f /var/opt/mssql/log/errorlog | while read LOGLINE
do
   [[ "${LOGLINE}" == *"Using 'xpstar.dll' version"* ]] && pkill -P $$ tail
done

echo "Running SQL Scripts"
# Scan for SQL files and load them in
for file in /sql-data/*.sql; do
    echo $file
    /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i $file 
done

/sql-data/setup.sql /sql-data/setup.sql

IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = 'Products')
BEGIN
    CREATE DATABASE Products;
END
GO

USE Products;
GO

The SQLCMD utility unfortunately defaults to QUOTED_IDENTIFIER OFF for backwards compatibility reasons. 不幸的是,出于向后兼容性原因,SQLCMD实用程序默认为QUOTED_IDENTIFIER OFF Specify the -I argument so that QUOTED_IDENTIFIER ON is used. 指定-I参数,以便使用QUOTED_IDENTIFIER ON

/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i $file -I

Tools like SQL Server Management Studio and Datagrip have Quoted Identifier turned on by default. SQL Server Management Studio和Datagrip等工具默认启用了引号标识符。 You must manually enable it in SQLCMD by modifying your SQL Scripts to SET QUOTED_IDENTIFIER ON 您必须通过将SQL脚本修改为SET QUOTED_IDENTIFIER ON在SQLCMD中手动启用它

You would modify your setup.sql script like this: 您可以像这样修改setup.sql脚本:

/sql-data/setup.sql /sql-data/setup.sql

SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = 'Products')
BEGIN
    CREATE DATABASE Products;
END
GO

USE Products;
GO

暂无
暂无

声明:本站的技术帖子网页,遵循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’ SQL 查询通知 - 更新失败,因为以下 SET 选项的设置不正确:'QUOTED_IDENTIFIER' - SQL Query Notifications - UPDATE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER' `bcp in` 失败并显示“插入失败,因为以下 SET 选项设置不正确:'QUOTED_IDENTIFIER'” - `bcp in` fails with "INSERT 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' 删除所有表时出错“DELETE 失败,因为以下 SET 选项的设置不正确:'QUOTED_IDENTIFIER'” - Error deleting all tables "DELETE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'" 过滤的唯一索引导致更新由于错误的“ QUOTED_IDENTIFIER”设置而失败 - Filtered Unique Index causing UPDATE to fail because incorrect 'QUOTED_IDENTIFIER' settings UPDATE失败,因为以下SET选项的设置不正确:'ARITHABORT' - UPDATE failed because the following SET options have incorrect settings: 'ARITHABORT' INSERT失败,因为以下SET选项的设置不正确:“ ARITHABORT”。 - INSERT failed because the following SET options have incorrect settings: 'ARITHABORT'. SQL SERVER 和 SET ANSI_NULLS ON, SET QUOTED_IDENTIFIER ON - SQL SERVER and SET ANSI_NULLS ON, SET QUOTED_IDENTIFIER ON SQL Server 2008 SET QUOTED_IDENTIFIER OFF问题 - SQL Server 2008 SET QUOTED_IDENTIFIER OFF problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM