Sitecore 9 login: An Error Occurred, String or binary data would be truncated

This is caused by Sitecore generating a login ticket too long to be stored in the database, hence the data would be truncated. I'm not sure why this happens, but it looks like the URL (or part of the URL) is included in the ticket, causing it to be longer that the datatype in the database allows.

Here's the stacktrace from the log:

Nested Exception
Exception: System.Data.DataException
Message: Error executing SQL command: INSERT INTO [Properties] ( [Key], [Value] ) VALUES ( @name, @value )
Nested Exception
Exception: System.Data.SqlClient.SqlException
Message: String or binary data would be truncated.
The statement has been terminated.
Source: .Net SqlClient Data Provider



The solution is to delete the ticket directly in the core database, consequently forcing Sitecore to generate a new one on next login. Run the following SQL query and make sure to target the effected user by replacing "Username" with something unique that identifies the user.

DELETE FROM [Project_Core].[dbo].[Properties]
WHERE [Project_Core].dbo.Properties.[Key] LIKE 'CORE_SC_TICKET%'
AND [Project_Core].dbo.Properties.[Value] LIKE '%Username%'