Skip to content

getIsSameDatabaseChecker catches wrong exception on SQL_SERVER #61579

@Matt-PMCT

Description

@Matt-PMCT

Symfony version(s) affected

6.4.23

Description

I was attempting to enable Database Sessions on my Symfony application. However, when I did this, I started receiving an error:

php bin/console doctrine:schema:update --dump-sql

In ExceptionConverter.php line 60:

An exception occurred while executing a query: SQLSTATE [42S02, 3701]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot drop the table 'schema_subscriber_check_fe58486cb401d4', because it does not exist or you do not have permission.

I tried many things to resolve this error. Strangely, one thing that worked was granting my database user ALL permissions to the entire database server, but this was unacceptable to me from a security standpoint.

After diving into the code I found the following in the the AbstractSchemaListener.php file :

            try {
                $schemaManager->dropTable($checkTable);
                return false;
            } catch (TableNotFoundException) {
                return true;
            }

However, the exception that SQL Server uses appears to be a DatabaseObjectNotFoundException instead of a TableNotFoundException.

How to reproduce

Create a Symfony project, Create a MS SQL server database and user, then attempt to enable Database Sessions with that server as the target and run the CLI command: php bin/console doctrine:schema:update --dump-sql

Possible Solution

Modifying this section of code to this fixes the error and allows the functionality to work correctly:

            try {
                $schemaManager->dropTable($checkTable);

                return false;
            } catch (TableNotFoundException) {
                return true;
            } catch (DatabaseObjectNotFoundException) {
                return true;
            }

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