首先,我尝试搜索类似问题的答案:Developer Command Propmt 和这个: Cannot open database "test" requested by the login. The login failed. Login failed for user 'xyz\ASPNET' 我什至格式化了我的电脑。但我仍然有这个问题。很长一段时间我的应用程序连接到本地 MSSQl 服务器没有任何问题。但有一刻我决定使用 Server Menager 删除我的数据库。这开始发生了。 我要连接的 C# 代码(它在我决定删除数据库并替换它之前有效):
using (SqlConnection con = new SqlConnection(@"Server=tcp:DESKTOP-56F50SS;Database=Test;
User ID=sa;Password=Temptemp;Trusted_Connection=False;Encrypt=False;"))
最佳答案
看来我们无法设置 TCP/IP 的权限。请检查 TCP/IP 的权限。
启用TCP/IP网络协议(protocol)
Start SQL Server Configuration Manager. Click Start, point to All Programs, and click Microsoft SQL Server. Click Configuration Tools, and then click SQL Server Configuration Manager.
In SQL Server Configuration Manager, in the console pane, expand SQL Server Network Configuration.
In the console pane, click Protocols for .
In the details pane, right-click TCP/IP, and then click Enable.
In the console pane, click SQL Server Services.
In the details pane, right-click SQL Server (), and then click Restart, to stop and restart the SQL Server service.
关于c# - 无法打开登录请求的数据库 "Test"。登录失败。用户 'sa' 登录失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48435048/