How to fix Error 221 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 221 – FIPS Warning (Implicit Conversion)

Why This Error Happens

This warning occurs when SQL Server 2025 detects an implicit data type conversion between incompatible types (%ls to %ls) during query execution, such as converting between varchar and specific numeric or date types under FIPS (Federal Information Processing Standards) compliance mode. FIPS flagging is stricter in SQL Server 2025 and Windows Server 2025 due to enhanced ANSI SQL compliance checks introduced to align with federal security baselines. This typically stems from legacy T-SQL code, stored procedures, or application queries that rely on SQL Server’s automatic type coercion instead of explicit CAST or CONVERT functions.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query or Procedure

  • Enable SQL Server Profiler or Extended Events to capture the exact query triggering Error 221.
  • Filter Extended Events session on error_reported with Error Number = 221.
  • Note the two data types referenced in the %ls to %ls placeholders (e.g., varchar to datetime).

Step 2: Modify T-SQL Code to Use Explicit Conversions

  • Locate the identified query in your stored procedure, view, or application code.
  • Replace implicit conversions with explicit CAST(column AS target_type) or CONVERT(target_type, column, style).
  • Example fix:
  -- Before (implicit conversion)
  SELECT * FROM Orders WHERE OrderDate = '2025-01-01'

  -- After (explicit conversion)
  SELECT * FROM Orders WHERE OrderDate = CONVERT(datetime, '2025-01-01', 121)

Step 3: Check FIPS Compliance Settings

  • Open SQL Server Configuration Manager on Windows Server 2025 / Windows 11.
  • Navigate to SQL Server Network Configuration > Protocols and confirm FIPS enforcement policy under Group Policy: Computer Configuration > Windows Settings > Security Settings > Local Policies > Security Options > System Cryptography: Use FIPS compliant algorithms.
  • If FIPS mode is enforced by organizational policy, ensure all T-SQL scripts are updated rather than disabling FIPS (not recommended for compliance environments).

Step 4: Update Database Compatibility Level

  • Run the following command to check current compatibility level:
  SELECT name, compatibility_level FROM sys.databases WHERE name = 'YourDatabaseName';
  • Update to the latest supported level for SQL Server 2025 (170) if the database is running on an older compatibility level:
  ALTER DATABASE YourDatabaseName SET COMPATIBILITY_LEVEL = 170;

Step 5: Apply Latest Cumulative Update (CU)

  • Verify current SQL Server build via:
  SELECT @@VERSION;
  • Download and install the latest Cumulative Update for SQL Server 2025 from the Microsoft Update Catalog, as early builds may have known issues with FIPS-mode type-checking warnings being overly aggressive.

Alternative or Verification Steps

  • After applying fixes, re-run the original query or execute the stored procedure to confirm Error 221 no longer appears in the SQL Server Error Log (SQL Server Management Studio > Management > SQL Server Logs).
  • As an alternative, if immediate code refactoring is not feasible, use SET ANSI_WARNINGS OFF at the session level as a temporary workaround — however, this is not recommended for production or FIPS-regulated environments and should only be used for short-term testing.