Troubleshooting Guide: SQL Server Error 4012 – Invalid TDS Collation
Why This Error Happens
Error 4012 occurs when the Tabular Data Stream (TDS) packet sent to SQL Server 2025 contains a collation identifier that the server cannot recognize or map to a valid collation in its internal collation table. This typically happens due to a mismatch between client driver versions and the server’s collation set, a corrupted sqlncli or msodbcsql driver installation, or an outdated client library attempting to negotiate a collation introduced in a newer SQL Server version that the driver doesn’t understand. It can also surface after an in-place upgrade where system databases retain a legacy collation reference that conflicts with newly introduced server-level collation metadata.
Step-by-Step Resolution Guide
Step 1: Verify and Update Client Drivers
- Confirm which driver the failing application uses (ODBC, OLE DB, or JDBC) via Event Viewer under Windows Logs > Application.
- Download and install the latest Microsoft ODBC Driver or
msodbcsql18.msifrom the official Microsoft Download Center. - Restart the application pool or client service after installation to force driver reload.
Step 2: Check Server Collation Configuration
- Open SQL Server Management Studio (SSMS) and run:
SELECT SERVERPROPERTY('Collation');
- Compare this output against the collation expected by the client connection string.
- If mismatched, update the connection string or application config file (
appsettings.json,web.config, or DSN entry) to explicitly specify the correct collation parameter.
Step 3: Rebuild or Repair System Databases
- Open an elevated Command Prompt on Windows Server 2025.
- Navigate to the SQL Server binn directory, typically:
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Binn
- Run a repair install using the setup media:
setup.exe /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=BUILTIN\Administrators /SAPWD=<StrongPassword>
- This resets
master,model,msdb, andtempdbcollation metadata to a known-good state.
Step 4: Clear TDS Endpoint Cache and Restart Services
- Open Services.msc on Windows Server 2025 / Windows 11.
- Restart the SQL Server (MSSQLSERVER) and SQL Server Browser services to flush cached TDS negotiation parameters.
- If using a named instance, restart the corresponding SQL Server (InstanceName) service as well.
Alternative or Verification Steps
- Test the fix by connecting via
sqlcmd -S <ServerName> -E -Q "SELECT @@VERSION"— a successful connection with no 4012 error confirms resolution. - If the error persists, create a new client alias using SQL Server Configuration Manager with explicit TCP/IP protocol settings and a matching collation flag to bypass any cached negotiation data.