Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Incorrect SET Options' Error When Building Database Project

We are using Visual Studio and a database project to generate our database.

I just made a number of database changes (including adding a new table named Correspondence) imported those changes into the database project, and attempted to deploy (rebuild) the database.

When I do, I get the following error:

Creating [dbo].[Correspondence]... Msg 1934, Level 16, State 1, Server (Server Name), Line 1 CREATE TABLE failed because the following SET options have incorrect settings : 'ANSI_WARNINGS, ANSI_PADDING'. 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.

Can anyone explain this error to me, and help me resolve it? Here's the script the database project uses to create this table.

PRINT N'Creating [dbo].[Correspondence]...'; GO  SET ANSI_NULLS, QUOTED_IDENTIFIER ON; GO  CREATE TABLE [dbo].[Correspondence] (     [Id]                INT              IDENTITY (1, 1) NOT NULL,     [WorkbookId]        INT              NOT NULL,     [ProviderId]        UNIQUEIDENTIFIER NOT NULL,     [MessageThreadId]   INT              NOT NULL,     [MessageThreadType] AS               ((1)) PERSISTED NOT NULL ); GO  SET ANSI_NULLS, QUOTED_IDENTIFIER OFF; GO  PRINT N'Creating PK_Correspondence...'; GO  ALTER TABLE [dbo].[Correspondence] ADD CONSTRAINT [PK_Correspondence] PRIMARY KEY CLUSTERED ([Id] ASC)     WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF,     IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF); GO 
like image 280
Jonathan Wood Avatar asked Feb 10 '12 22:02

Jonathan Wood


1 Answers

According to BOL:

Indexed views and indexes on computed columns store results in the database for later reference. The stored results are valid only if all connections referring to the indexed view or indexed computed column can generate the same result set as the connection that created the index.

In order to create a table with a persisted, computed column, the following connection settings must be enabled:

SET ANSI_NULLS ON SET ANSI_PADDING ON SET ANSI_WARNINGS ON SET ARITHABORT ON SET CONCAT_NULL_YIELDS_NULL ON SET NUMERIC_ROUNDABORT ON SET QUOTED_IDENTIFIER ON 

These values are set on the database level and can be viewed using:

SELECT      is_ansi_nulls_on,     is_ansi_padding_on,     is_ansi_warnings_on,     is_arithabort_on,     is_concat_null_yields_null_on,     is_numeric_roundabort_on,     is_quoted_identifier_on FROM sys.databases 

However, the SET options can also be set by the client application connecting to SQL Server.

A perfect example is SQL Server Management Studio which has the default values for SET ANSI_NULLS and SET QUOTED_IDENTIFIER both to ON. This is one of the reasons why I could not initially duplicate the error you posted.

Anyway, to duplicate the error, try this (this will override the SSMS default settings):

SET ANSI_NULLS ON SET ANSI_PADDING OFF SET ANSI_WARNINGS OFF SET ARITHABORT OFF SET CONCAT_NULL_YIELDS_NULL ON  SET NUMERIC_ROUNDABORT OFF SET QUOTED_IDENTIFIER ON GO  CREATE TABLE T1 (     ID INT NOT NULL,     TypeVal AS ((1)) PERSISTED NOT NULL )  

You can fix the test case above by using:

SET ANSI_PADDING ON SET ANSI_WARNINGS ON 

I would recommend tweaking these two settings in your script before the creation of the table and related indexes.

like image 165
8kb Avatar answered Sep 24 '22 16:09

8kb