Skip to content

Table not found error is not returning TableNotFoundException for MSSQL #6747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MaximilianGewers opened this issue Jan 28, 2025 · 2 comments

Comments

@MaximilianGewers
Copy link

MaximilianGewers commented Jan 28, 2025

Bug Report

Q A
Version My current 3.9.4 - but Also occurs on 4.2.2
Previous Version if the bug is a regression 3.8.2

Summary

I am using a MSSQL database (mcr.microsoft.com/mssql/server:2019-latest) and with Symfony (6.4). Symfony through doctrine has features that interact with the DB. Which have stopped working and my suspicion is a DBAL bug.

Current behavior

The first create and drop works as expected (the table does get created and dropped), however on the third drop (where I suspect the bug lies) a PDOException is being thrown with the message:

An exception occurred while executing a query: SQLSTATE[42S02]: [Microsoft]  
  [ODBC Driver 18 for SQL Server][SQL Server]Cannot drop the table 'schema_su  
  bscriber_check_4e0c48ec448e18', because it does not exist or you do not hav  
  e permission.

The this drop is surrounded by a try catch explicitly listening to a Doctrine\DBAL\Exception\TableNotFoundException. I am using a SA( System Admin) account and should not have any permission issues.

Expected behavior

I believe a Doctrine\DBAL\Exception\TableNotFoundException should be thrown in this case instead as the table is not found.

How to reproduce

A project with symfony and a MSSQL DB. Then run bin/console doctrine:schema:validate

composer.json

        "doctrine/annotations": "*",
        "doctrine/dbal": "^4.2",
        "doctrine/doctrine-bundle": "^2.13",
        "doctrine/doctrine-migrations-bundle": "^3.4",
        "doctrine/orm": "^3.3",
        "symfony/cache": "6.4.*",
        "symfony/console": "6.4.*",
        "symfony/debug-bundle": "6.4.*",
        "symfony/dotenv": "6.4.*",
        "symfony/flex": "^2.4",
        "symfony/framework-bundle": "6.4.*",
        "symfony/http-client": "6.4.*",
        "symfony/mailer": "6.4.*",
        "symfony/monolog-bundle": "^3.8",
        "symfony/property-access": "6.4.*",
        "symfony/property-info": "6.4.*",
        "symfony/proxy-manager-bridge": "6.4.*",
        "symfony/rate-limiter": "6.4.*",
        "symfony/runtime": "6.4.*",
        "symfony/security-bundle": "6.4.*",
        "symfony/serializer": "6.4.*",
        "symfony/stimulus-bundle": "^2.14",
        "symfony/uid": "6.4.*",
        "symfony/webpack-encore-bundle": "^2.1",
        "symfony/yaml": "6.4.*"

WIP - I am working on a way to share some code or a repo.

@morozov
Copy link
Member

morozov commented Apr 6, 2025

Please provide more details on reproducing the issue.

@jimpass2a
Copy link

jimpass2a commented Apr 29, 2025

Hi,

I'm encountering the exact same problem with Doctrine DBAL and SQL Server.

Here is my setup:

  • Symfony 6.4.20
  • PHP 8.2.28
  • Microsoft ODBC Driver 18 for SQL Server
  • PDO_SQLSRV extension 5.12.1
  • Doctrine DBAL 3.9
  • SQL Server 2019

Problem:
When I run doctrine:schema:update --force (or doctrine:migrations:diff), Doctrine creates a temporary table like schema_subscriber_check_* and tries to drop it later.
SQL Server raises an error:

SQLSTATE[42S02]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot drop the table 'schema_subscriber_check_xxxxx' because it does not exist or you do not have permission.

  • This issue appeared after upgrading from PHP 8.1 to PHP 8.2.
  • With PHP 8.1, the pdo_sqlsrv driver often automatically emulated prepared statements, so the problem did not occur.
  • With PHP 8.2 and PDO_SQLSRV 5.12+, strict server-side prepares are enforced, causing SQL Server to strictly check object existence during the prepare phase.

So it is impossible to use doctrine:schema:update and doctrine:migrations:diff with SQL Server + Doctrine DBAL now.

  • Manual migrations are the only reliable workaround at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants