SQL Server Errors: The Complete Guide

Every entry here is a message somebody pasted into a search box while something was broken. This page exists to get you from that message to the cause quickly, which is a different job from explaining what SQL Server errors are in general.

Three Steps From Message to Cause

01

Get the real message

The client softens it; the server error log names the real cause, and most posts here start by reading it.

02

Check the severity

Severity tells you whether a statement failed or the server is in trouble. Below 17 it is a morning job. From 17 up it is tonight’s.

03

Find the error below

Paste the message or type the number. Every entry says what it actually means, and links to the full write-up where one exists.

Read the log, newest first:EXEC xp_readerrorlog 0, 1, NULL, NULL, NULL, NULL, N'desc';

Understanding Severity

Severity is the fastest triage you have, because it separates “a query failed” from “the server is in trouble” before you have understood anything else. SQL Server Error Severities Explained covers every level, how to read one in SSMS, what TRY...CATCH will and will not catch, and where errors are stored.


Find an Error

54 errors, 50 with a full write-up. The rest carry enough to tell you what you are looking at. Paste the message, or type the number.

54 of 54
18456Login failed for userSEV 14Login failed for user 'X'.The client only ever sees State 1. The real state is in the error log and names the cause.18452Login from an untrusted domainSEV 14referenceLogin failed. The login is from an untrusted domain and cannot be used with Integrated authentication.Windows authentication could not be negotiated, often SPN or trust related rather than a password problem.18470Login disabledSEV 14referenceLogin failed for user 'X'. Reason: The account is disabled.The login exists and the password may even be right. It is switched off.4060Cannot open database requested by the loginSEV 11Cannot open database "X" requested by the login. The login failed.The login is fine. The database named in the connection string is missing, offline or not permitted.4064Cannot open user default databaseSEV 11Cannot open user default database. Login failed.The login's default database is unavailable. Fixable without touching the database.17806SSPI handshake failedSEV 20referenceSSPI handshake failed with error code 0x8009030c.Kerberos or NTLM could not complete. Usually a duplicate or missing SPN, or clock skew.10054Existing connection was forcibly closedA connection was successfully established with the server, but then an error occurred during the login process.Not a login problem. The handshake failed before credentials were checked.Certificate chain not trustedThe certificate chain was issued by an authority that is not trusted.The client now validates the certificate by default. Your server did not change.53Network path was not foundreferenceA network-related or instance-specific error occurred. (provider: Named Pipes Provider, error: 40)The instance was never reached. Name resolution, port, firewall or the Browser service.300VIEW SERVER STATE permission deniedSEV 14VIEW SERVER STATE permission was denied on object 'server', database 'master'.Every interesting DMV is behind this. Database roles cannot reach it.229SELECT permission deniedSEV 14referenceThe SELECT permission was denied on the object 'X', database 'Y', schema 'dbo'.Object-level permission, or a DENY inherited from a role.262CREATE DATABASE permission deniedSEV 16CREATE DATABASE permission denied in database 'master'.Needs dbcreator or sysadmin, and it is the same shape for most CREATE permissions.916Not able to access the database under the current security contextSEV 14referenceThe server principal "X" is not able to access the database "Y" under the current security context.Common in SSMS Object Explorer when a login has no user in one database on the instance.15023User already exists in current databaseSEV 16User, group, or role 'X' already exists in the current database.The classic orphaned user after a restore. The user exists, its SID no longer matches a login.15138Database principal owns a schemaSEV 16The database principal owns a schema in the database, and cannot be dropped.Reassign the schema owner first, then drop the user.15517Cannot execute as the database principalSEV 16referenceCannot execute as the database principal because the principal "dbo" does not exist.Usually a database whose owner SID no longer resolves, after a restore or a domain change.927Database is in the middle of a restoreSEV 14Database 'X' cannot be opened. It is in the middle of a restore.RESTORING state. The question is whether a restore is running or the database was stranded.3201Cannot open backup deviceSEV 16Cannot open backup device 'X'. Operating system error 5(Access is denied.).Almost always the SQL Server service account, not your own account, lacking access to the path.3241Media family on device is incorrectly formedSEV 16The media family on device 'X' is incorrectly formed. SQL Server cannot process this media family.Wrong file, truncated copy, or a backup from a newer version being restored to an older one.3013Restore database is terminating abnormallySEV 16RESTORE DATABASE is terminating abnormally.The companion message, never the cause. The error immediately above it is the real one.3154The backup set holds a backup of a database other than the existing oneSEV 16The backup set holds a backup of a database other than the existing 'X' database.Restoring over a different database needs WITH REPLACE, and deserves a pause first.
33111Cannot find server certificateSEV 16referenceCannot find server certificate with thumbprint 'X'.A TDE-encrypted backup restored to an instance without the certificate. Restore the certificate first.
9002Transaction log is fullSEV 17The transaction log for database 'X' is full due to 'LOG_BACKUP'.The reason in quotes is the diagnosis, and it is rarely solved by shrinking.1105Could not allocate space, filegroup is fullSEV 17Could not allocate space for object 'X' in database 'Y' because the 'PRIMARY' filegroup is full.Data file, not log. Autogrowth off, disk full, or a size cap reached.5123CREATE FILE encountered operating system errorSEV 16CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open the file 'X'.Service account permissions on the target folder, or a path that does not exist.5030Database could not be exclusively lockedSEV 16The database could not be exclusively locked to perform the operation.Something is connected. Common when setting a database to single user or restoring over it.945Database cannot be opened due to inaccessible filesSEV 16Database 'X' cannot be opened due to inaccessible files or insufficient memory or disk space.The files are missing, the service account lost access, or the volume is gone.
5171Not a primary database fileSEV 16reference'X.mdf' is not a primary database file.A corrupt or wrong file being attached, or a file copied while the instance was running.
1205Deadlock victimSEV 13Transaction (Process ID 52) was deadlocked on lock resources with another process and has been chosen as the deadlock victim.The engine picked the cheaper transaction to kill. The fix is in the access pattern, not the error.1222Lock request time out period exceededSEV 16Lock request time out period exceeded.Blocking, not deadlock. Something held a lock longer than the timeout allowed.701Insufficient system memorySEV 19There is insufficient system memory in resource pool 'default' to run this query.Real memory pressure, or a single query asking for far more than it should.8645Timeout waiting for memory resourcesSEV 17A timeout occurred while waiting for memory resources to execute the query.RESOURCE_SEMAPHORE waits. Query memory grants are the thing to look at.
8623Query processor ran out of internal resourcesSEV 16referenceThe query processor ran out of internal resources and could not produce a query plan.Nearly always an enormous IN list or a generated query of extreme size.
468Cannot resolve the collation conflictSEV 16Cannot resolve the collation conflict between 'X' and 'Y' in the equal to operation.Two sides of a comparison carry different collations. It surfaces when a query joins or compares across databases, or against tempdb, and the fix is COLLATE DATABASE_DEFAULT on the comparison rather than changing a column.207Invalid column nameSEV 16Invalid column name 'X'.Typo, wrong alias, or a column that exists in a different environment to the one you are on.208Invalid object nameSEV 16Invalid object name 'dbo.X'.Wrong database context or schema more often than a missing object.245Conversion failed when convertingSEV 16Conversion failed when converting the varchar value 'abc' to data type int.Implicit conversion meeting a value that will not convert. Also a performance smell.2627Violation of PRIMARY KEY constraintSEV 14referenceViolation of PRIMARY KEY constraint 'PK_X'. Cannot insert duplicate key in object 'dbo.Y'.A duplicate insert, often a retry that succeeded the first time.2601Cannot insert duplicate key row in unique indexSEV 14referenceCannot insert duplicate key row in object 'dbo.X' with unique index 'IX_Y'.Same as 2627 but from a unique index rather than a primary key.547Conflict with a FOREIGN KEY constraintSEV 16The INSERT statement conflicted with the FOREIGN KEY constraint 'FK_X'.The parent row does not exist, or you are deleting one that still has children.8152String or binary data would be truncatedSEV 16String or binary data would be truncated.Pre-2019 it will not tell you which column. 2019 and later name the column and the value.2628String or binary data would be truncated in tableSEV 16String or binary data would be truncated in table 'db.dbo.T', column 'c'. Truncated value: 'X'.The 2019 and later version of 8152. It names the table, the column and the value.102Incorrect syntax nearSEV 15Incorrect syntax near 'X'.Often a compatibility level or version issue rather than a real typo, when the same code works elsewhere.823I/O error, the operating system reported a failureSEV 24The operating system returned error 21 to SQL Server during a read at offset 0x… in file 'X'.The storage layer failed the request. This is hardware or driver, not SQL Server.824Logical consistency-based I/O errorSEV 24SQL Server detected a logical consistency-based I/O error: incorrect checksum.The read succeeded and the page was wrong. Check the backups before anything else.825Read-retry succeededSEV 10A read of the file 'X' at offset … succeeded after failing N attempt(s).The quiet one. Severity 10 so nothing alerts, and it is the warning before 823 and 824.
605Attempt to fetch logical page belongs to a different objectSEV 21referenceAttempt to fetch logical page … in database … belongs to object …, not to object …Allocation corruption. Stop and go to backups.
3417Cannot recover the master databaseSEV 21Cannot recover the master database. SQL Server is unable to run.The instance will not start. Master is damaged, moved, or its permissions changed.622The filegroup has no files assigned to itSEV 16The filegroup "X" has no files assigned to it. Tables, indexes, text columns, ntext columns, and image columns cannot be populated on this filegroup until a file is added.The filegroup was created and no file was ever added. CREATE TABLE on it succeeds, so the failure lands later, at the first insert.5042The filegroup cannot be removed because it is not emptySEV 16The filegroup 'X' cannot be removed because it is not empty.Something still lives on it, often a nonclustered index rather than the table you were thinking of. Objects first, then the files, then the filegroup.515Cannot insert the value NULL into columnSEV 16Cannot insert the value NULL into column 'X', table 'Y'; column does not allow nulls. INSERT fails.Leaving a NOT NULL column out of the insert gives the same message as passing NULL, so check your column list before hunting for NULLs. A default rescues the omitted case but not an explicit NULL.213Column name or number of supplied values does not matchSEV 16Column name or number of supplied values does not match table definition.The shape of the insert does not match the table. The static form fails at compile time, so TRY/CATCH does not catch it, and naming the columns does not help INSERT … EXEC.1934SET options have incorrect settingsSEV 16INSERT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes.The connection writing to a table with a filtered index or indexed view has the wrong SET options. Reads still work, which is why it usually shows up as one failing job. SSMS sets QUOTED_IDENTIFIER ON and sqlcmd does not.5120Unable to open the physical fileSEV 16Unable to open the physical file "X". Operating system error 5: "5(Access is denied.)".Read the operating system error, not the SQL one. Error 5 has two different causes: the file is already open (often by SQL Server itself), or the service account cannot read it. On an attach it arrives with Msg 1802, and TRY/CATCH only sees the 1802.
Nothing matches that yet. The pool grows as errors come up, so it is worth searching the site as well.

Common Questions

Where does SQL Server keep the real error?
The SQL Server error log, which is not the same as what the client is shown. Read it with EXEC xp_readerrorlog 0, 1, N'search term'; or open ERRORLOG in the instance’s Log folder if you cannot connect at all.
Which errors should actually wake someone up?
Severity 17 and above. Below that a statement failed and the server is fine. Severity 20 to 25 close the connection and get written to the error log, so those are the ones worth alerting on.
Why did my application see a different error?
Severity 20 and above terminate the connection, so the client often reports a generic transport failure instead of the real message. That is why the error log is the first stop rather than the last.
The error is not listed here.
The pool grows as errors come up. In the meantime sys.messages holds every message text and severity the instance knows about, and the severity alone tells you whether you are dealing with a statement problem or a server problem. Error Severities Explained, first in Related Scripts below, is the page that turns that number into a decision.

Every error on this page is also reachable by an AI assistant through the sqldba MCP server. Its lookup_error tool takes a number or a phrase from the message and returns the same verified entry, with the link back to the write-up attached.

Related Scripts

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *