2012-02-10 30 views
31

Estamos utilizando Visual Studio y un proyecto de base de datos para generar nuestra base de datos.Error 'Opciones SET incorrectas' al crear el proyecto de base de datos

Acabo de realizar una serie de cambios en la base de datos (incluida la adición de una nueva tabla llamada Correspondence) importé esos cambios en el proyecto de base de datos e intenté implementar (reconstruir) la base de datos.

Cuando lo hago, me sale el siguiente 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.

¿Puede alguien explicar este error para mí, y me ayude a resolverlo? Aquí está el script que el proyecto de base de datos usa para crear esta tabla.

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 

Respuesta

69

Según 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.

Con el fin de crear una tabla con una columna PERSISTED computarizada, los siguientes parámetros de conexión debe estar habilitado: se establecen

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 

Estos valores en el nivel de la base de datos y se puede ver usando:

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 

Sin embargo, the SET options can also be set by the client application se conecta a SQL Server.

Un ejemplo perfecto es SQL Server Management Studio que tiene los valores predeterminados para SET ANSI_NULLS y SET QUOTED_IDENTIFIER para ON. Esta es una de las razones por las que no pude duplicar inicialmente el error que publicó.

De todos modos, para duplicar el error, intente esto (esto anulará el SSMS configuración predeterminada):

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 
) 

puede solucionar el caso de la prueba anterior usando:

SET ANSI_PADDING ON 
SET ANSI_WARNINGS ON 

lo recomiendo ajustar estas dos configuraciones en su secuencia de comandos antes de la creación de la tabla y los índices relacionados.

+1

Gracias, he podido utilizar su publicación para que funcione. Desafortunadamente, es un poco más complejo que simplemente agregar sentencias SET porque nuestra secuencia de comandos se crea dinámicamente utilizando un proyecto de base de datos de Visual Studio y con frecuencia se recrea automáticamente desde una base de datos modificada. También hay un error que impide que algunas de estas configuraciones se establezcan en las propiedades para objetos individuales. Más problemas, pero ahora se compilará. –

+2

Esto fue realmente útil. De todos modos, en mi caso, tuve que configurar el NUMERIC_ROUNDABORT en OFF – gigi

+1

NUMERIC_ROUNDABOUT debe ser NUMERIC_ROUNDABORT, pero la edición de 6 caracteres me limita a corregir esto. – Blackunknown

2

he encontrado la solución para este problema:

  1. vaya a las propiedades del servidor.
  2. Seleccione la ficha Conexiones.
  3. Compruebe si la opción ansi_padding está desmarcada.
+0

Esos son solo los valores predeterminados de la base de datos. Los ajustes generalmente son anulados por la conexión y/o SSMS. – Suncat2000

2

En mi caso, estaba intentando crear una tabla de una base de datos a otra en MS SQL Server 2012.Al hacer clic derecho sobre una mesa y seleccionando Tabla de secuencias de comandos como> DROP y crear Para> Nuevo Editor de consultas Ventana, escritura siguiente fue creado:

USE [SAMPLECOMPANY] 
GO 

ALTER TABLE [dbo].[Employees] DROP CONSTRAINT [FK_Employees_Departments] 
GO 

/****** Object: Table [dbo].[Employees] Script Date: 8/24/2016 9:31:15 PM ******/ 
DROP TABLE [dbo].[Employees] 
GO 

/****** Object: Table [dbo].[Employees] Script Date: 8/24/2016 9:31:15 PM ******/ 
SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 

SET ANSI_PADDING ON 
GO 

CREATE TABLE [dbo].[Employees](
    [EmployeeId] [int] IDENTITY(1,1) NOT NULL, 
    [DepartmentId] [int] NOT NULL, 
    [FullName] [varchar](50) NOT NULL, 
    [HireDate] [datetime] NULL 
CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED 
(
    [EmployeeId] 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 

SET ANSI_PADDING OFF 
GO 

ALTER TABLE [dbo].[Employees] WITH CHECK ADD CONSTRAINT [FK_Employees_Departments] FOREIGN KEY([DepartmentId]) 
REFERENCES [dbo].[Departments] ([DepartmentID]) 
GO 

ALTER TABLE [dbo].[Employees] CHECK CONSTRAINT [FK_Employees_Departments] 
GO 

Sin embargo cuando se ejecuta por encima de la escritura se vuelve el error:

SELECT failed because the following SET options have incorrect settings: '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.

la solución que he encontrado: Activación de la configuración de la parte superior de la secuencia de comandos de esta manera:

USE [SAMPLECOMPANY] 
GO 
/****** Object: Table [dbo].[Employees] Script Date: 8/24/2016 9:31:15 PM ******/ 
SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 

SET ANSI_PADDING ON 
GO 

ALTER TABLE [dbo].[Employees] DROP CONSTRAINT [FK_Employees_Departments] 
GO 

/****** Object: Table [dbo].[Employees] Script Date: 8/24/2016 9:31:15 PM ******/ 
DROP TABLE [dbo].[Employees] 
GO 



CREATE TABLE [dbo].[Employees](
    [EmployeeId] [int] IDENTITY(1,1) NOT NULL, 
    [DepartmentId] [int] NOT NULL, 
    [FullName] [varchar](50) NOT NULL, 
    [HireDate] [datetime] NULL 
CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED 
(
    [EmployeeId] 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 [dbo].[Employees] WITH CHECK ADD CONSTRAINT [FK_Employees_Departments] FOREIGN KEY([DepartmentId]) 
REFERENCES [dbo].[Departments] ([DepartmentID]) 
GO 

ALTER TABLE [dbo].[Employees] CHECK CONSTRAINT [FK_Employees_Departments] 
GO 

SET ANSI_PADDING OFF 
GO 

esperanza esta hel pag.

+0

También tuve este mismo problema. Al usar SSMS para hacer clic con el botón secundario en crear script, se creó una secuencia de comandos que decía ... SET ANSI_PADDING ON, CREATE MyTable, SET ANSI_PADDING OFF, ALTER TABLE indices. Tuve que eliminar el ANSI_PADDING ANSI_PADDING auxiliar para ejecutar mi script. Nunca he visto esto antes. ¿Por qué SSMS lo script de una manera que no podría ejecutar? –

0

Para mí, simplemente establecer el nivel de compatibilidad a un nivel superior funciona bien. Para ver C.Level:

select compatibility_level from sys.databases where name = [your_database] 
Cuestiones relacionadas