System.Data.SqlClient.SqlConnection.OnError

Vijay Kumar 2,036 Reputation points
2023-01-20T07:22:52.02+00:00

Hi Team,

We are getting this error in SQL Server 2016 (SP3-CU1)

Error 50001, severity 11, state 1 was raised, but no message with that error number was found in sys.messages. If error is larger than 50000, make sure the user-defined message is added using sp_addmessage.    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,485 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 46,031 Reputation points
    2023-01-20T08:35:40.7266667+00:00

    If error is larger than 50000, make sure the user-defined message

    Error codes > 50000 are raised by your own SQL code, not by the database engine. So review your code, why it raises the error.

    See https://learn.microsoft.com/en-us/sql/t-sql/language-elements/raiserror-transact-sql?view=sql-server-ver16

    0 comments No comments

  2. Erland Sommarskog 117.2K Reputation points MVP
    2023-01-20T23:00:58.3233333+00:00

    Since this error appears to happen on connection, one could suspect that there is a LOGON trigger that raises error 50001 for some reason.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.