Troubleshooting Guide: SQL Server Error 298 – smalldatetime Overflow
Why This Error Happens
This error occurs because the datetime data type supports a date range of January 1, 1753 through December 31, 9999, while smalldatetime only supports January 1, 1900 through June 6, 2079. When SQL Server attempts an implicit or explicit conversion of a datetime value that falls outside the smalldatetime boundary, the engine throws Error 298 rather than truncating or rounding the value. This is most commonly caused by application default values, legacy data imports, or NULL/uninitialized date fields (e.g., 1/1/1900 edge cases or system dates like 9999-12-31) being pushed into a column or variable typed as smalldatetime.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Query or Column
- Run SQL Server Profiler or Extended Events to capture the exact query firing Error 298.
- Check the SQL Server Error Log (
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) for the timestamp correlating with the failure. - Look for
CASTorCONVERTstatements targetingsmalldatetimein stored procedures or application connection strings.
Step 2: Validate the Data Range in Source Columns
- Execute a validation query to find out-of-range values before conversion:
SELECT * FROM YourTable
WHERE YourDateColumn < '1900-01-01' OR YourDateColumn > '2079-06-06';
- Pay special attention to default constraints or ORM-generated dates (e.g., Entity Framework defaulting to
0001-01-01, which SQL Server maps to1900-01-01, but overflow occurs when app sends9999-12-31for “no expiration” logic).
Step 3: Modify the Column Data Type or Query Logic
- If historical/future dates are legitimate business data, alter the column definition to use
datetime2instead ofsmalldatetime:
ALTER TABLE YourTable
ALTER COLUMN YourDateColumn DATETIME2(0);
- If the column must remain
smalldatetime, update the application logic or stored procedure to cap/floor the value before insertion using aCASEstatement.
Step 4: Patch Application Connection Strings (If Applicable)
- For apps connecting via ODBC/OLEDB on Windows Server 2025, ensure the driver isn’t auto-casting
NULLC#DateTime.MinValueorDateTime.MaxValueobjects directly intosmalldatetimeparameters. - Update the parameter definition in your application code to explicitly use
SqlDbType.DateTimeinstead ofSqlDbType.SmallDateTimeif wide date ranges are expected.
Alternative or Verification Steps
- Verify the fix: Re-run the original failing transaction or ETL job; monitor the SQL Server Activity Monitor to confirm the query completes without throwing Error 298.
- Alternative fix: If you cannot alter the schema immediately, wrap the specific INSERT/UPDATE statement in a
TRY...CATCHblock to gracefully handle overflow errors and log the invalid record for manual review instead of halting the entire batch process.