That is a generic "could not connect to server" message and does not help diagnose the true problem in any way.
Since this is an intermittent issue, it is likely you have a network problem or the SQL Server is too busy to respond to the login request. You would have to look at the server when it is happening.
I would start here:
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/troubleshoot-connecting-to-the-sql-server-database-engine?view=sql-server-ver15#testing-a-local-connection