Skip to content

PdoSessionHandler creates invalid sess_data column for SQL Azure #62241

@adatta02

Description

@adatta02

Symfony version(s) affected

7.x

Description

I have a new Symfony project that's connecting to SQL Azure (server details below).

The DDL for the session table its using is:

CREATE TABLE sessions (sess_id NVARCHAR(128) NOT NULL, sess_data VARBINARY(MAX) NOT NULL, sess_lifetime INT NOT NULL, sess_time INT NOT NULL, PRIMARY KEY (sess_id));
CREATE INDEX sess_lifetime_idx ON sessions (sess_lifetime);

When I try to use the Session, ex. by logging in, I'm getting this SQL server error:

SQLSTATE[42000]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.

Changing the sess_data column to nvarchar(max) does fix it.

I can see in configureSchema it has the same issue:

https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php#L223

ProductVersion,12.0.2000.8
ProductLevel,RTM
Edition,SQL Azure
EngineEdition,5
EngineEditionValue,5
Collation,SQL_Latin1_General_CP1_CI_AS
IsClustered,
IsHadrEnabled,
SqlVersion,12.0.2000.8
SqlServicePack,RTM
SqlEdition,SQL Azure
SqlEngineEdition,5
SqlCollation,SQL_Latin1_General_CP1_CI_AS
FullVersionString,"Microsoft SQL Azure (RTM) - 12.0.2000.8 
	Oct  2 2025 00:38:42 
	Copyright (C) 2025 Microsoft Corporation
"

How to reproduce

  • Create an Azure SQL database
  • Setup a new Symfony project
  • Switch sessions to use PdoSessionHandler
  • Create the table

Possible Solution

No response

Additional Context

No response

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