SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user

SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding SQLSTATE[28000]: Login Failed for User

Encountering SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server] Login failed for user is a common frustration when bridging PHP applications with Microsoft SQL Server. The error message explicitly states that the credentials provided in your connection string do not match any valid login stored in the database engine, or that the authentication context cannot be established.

When you run into this issue after upgrading to ODBC Driver 17 or 18, it is tempting to assume the driver is incompatible or outdated. However, the error persists because the problem rarely lies within the driver version itself; instead, it usually stems from a mismatch between how your PHP application authenticates and how SQL Server expects it to authenticate.

The code snippet you are using employs the sqlsrv namespace with a standard DSN format:

$conn = new PDO("sqlsrv:Server=$servername;Database=$dbname", $username, $password);

This approach relies on SQL Server Authentication (also known as "Mixed Mode"). In this scenario, you must provide a login name and password that exist specifically within the SQL Server instance. If your $password variable is empty or contains whitespace, the database will reject the connection immediately, triggering the Login failed for user error.

A frequent pitfall involves mixing authentication modes. You mentioned configuring SQL Server to allow both Windows Authentication and SQL Server Authentication (Mixed Mode). While enabling Mixed Mode is a prerequisite for using $username and $password, simply toggling this setting on the server side does not automatically grant access to your application user. The specific login account defined in your PHP code must:

  1. Exist in the sys.sql_logins catalog view.
  2. Have a password set that matches exactly what is being sent from PHP.
  3. Possess appropriate permissions to connect to the target database.

If you are attempting to use Windows Authentication instead, the connection string syntax changes entirely. You would need to remove the $username and $password arguments and likely prefix the server address with a trusted domain or leave it as . for local connections, depending on your environment configuration:

$conn = new PDO("sqlsrv:Server=$servername;Database=$dbname", null, null);

In this Windows Auth context, PHP runs under an identity that SQL Server trusts via the Active Directory. If your IIS or CLI process is running as a local account (like IUSR or nobody) and not a domain-joined service account with database access, this method will also fail, often confusingly reporting a login failure.

Another subtle issue arises from how PHP handles empty strings versus null values in the connection string. If your intention is to use Windows Authentication but your code still passes an empty string ("") for the password, SQL Server might attempt to treat this as a SQL Logon attempt with an empty password rather than falling back to the current Windows identity. The ODBC driver interprets the parameters strictly; if you provide placeholders for username and password, it expects SQL authentication unless the connection string explicitly forces Kerberos or NTLM via specific flags.

To resolve this, verify the login exists in SQL Server Management Studio (SSMS) using SELECT name FROM sys.sql_logins WHERE name = '$username';. Ensure the password is not empty if you are using Mixed Mode. If switching to Windows Authentication, ensure your PHP process identity is explicitly added to the database users and mapped correctly.

If you require further assistance with configuring PHP-Driver-SQLSRV connections or need a robust connection handling strategy for your enterprise application, refer to the resources provided by https://laravelcompany.com.

Our network