Solution: Login failed for user 'sa'. Cause: Not associated with a trusted SQL Server connection.
I encountered this problem again during identity verification today, so I compiled my solution for sharing with friends who have had the same experience:
Brief description of the problem:
Login failed for user 'sa'. Cause: Not associated with a trusted SQL Server connection.
Explanation: An unhandled exception occurred during execution of the current web request. Please check the stack trace for more details about the error and where in the code that caused it.
Exception details: System.Data.SqlClient.SqlException: Login failed for user 'sa'. Cause: Not associated with a trusted SQL Server connection.
Source error:
Line 118: SqlCommand cmd=new SqlCommand(sql,con);
Line 119:
Line 120: con.Open();
Line 121:
My solution steps:
This problem is generally caused by SQL Server not integrating Windows authentication, so the solution is:
1 Open SQL Server Enterprise Manager.
2 Right-click on the server name and select "Edit SQL Server Registration Properties", then select "Use Windows Authentication" in the dialog box.
3 Try it, it doesn’t work. Looking at the security settings
4 Right-click the same, select "Properties", and then open the "Security" tab.
5 In the tab, select Authentication as "SQL Server and Windows", leaving the others unchanged