Skip to content

MSSQL IDENTITY_INSERT Issues #2752

@jedkirby

Description

@jedkirby

I've run into issues with the IDENTITY_INSERT on MSSQL using this package, on any version that's higher or equal to 2.5.11, however, I'm unable to identify the root cause of it.

Just to be clear, the following is not an issue on 2.5.10.

Migration Commands

I've been using DBAL to run the following from within a database migration:

$this->addSql("SET IDENTITY_INSERT TableName ON");

Then following that I'm doing this to insert fix a fixed ID row entry:

$this->addSql(
    "INSERT INTO TableName (id, title) VALUES (123, 'My Title');"
); 

And after that, turning off the ability to insert with identities:

$this->addSql("SET IDENTITY_INSERT TableName OFF");

The Issue

Regardless of whether I set the IDENTITY_INSERT to ON or not, I get the following error:

SQLSTATE [23000, 544]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Cannot insert explicit value for identity column in table 'TableName' when IDENTITY_INSERT is set to OFF.

Something somewhere in 2.5.11 is actually not performing the setting of the IDENTITY_INSERT.

Please could someone provide some help on this? I'm currently fixing my version of this package to 2.5.10, but that's not a long term solution.

System

Machine: Windows Server 2012 R2 Datacenter
PHP: 5.6.17

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions