Working with my project in debug I have no issues. However running it in IIS I am getting this error:
System.Data.SqlClient.SqlException: Login failed for us
add persist security info=True; in connection string.
kinda dumb, but I had a weird character (é) in my password. After omitting it, I no longer got the error.
I tried some of the suggested answers but it didn't resolve the issue. Finally I found out that the default connection timeout (not command timeout) is 15 seconds and once I increased it to 60 it almost never happened again.
simply add this to you connection string:
;Connection Timeout=60
I chose 60 seconds but you can put any value you think would fit the best to your needs.
Numpty here used SQL authentication
instead of Windows (correct)
when adding the login to SQL Server, which also gives you this error if you are using Windows auth.