我在本地计算机上运行了一个 SQL Server Express 2008 R2 实例,并且采用了“混合”身份验证,所以我可以使用 Windows 登录和 SQL Server 身份验证登录。启用了命名管道和 TCP/IP,并允许远程连接。我按以下步骤创建了一个新的登录和数据库:
1. 使用 SQL Server Management Studio Express 登录并创建一个新登录。 2. 使用新创建的登录作为所有者创建了一个新数据库。
如最后一张截图所示,“dbo” 是属于“mylogin” 登录名的“用户名”。我试图使用以下连接字符串连接,但它不起作用:
Data Source=(local)\sqlexpress;Initial Catalog=newdb;User id=mylogin;Password=mypass
在 SQL Server Management studio express 的错误日志中显示:“Login failed for user 'mylogin'. Reason: Failed to open the explicitly specified database. [CLIENT: xxx.xxx.x.xx]. Error: 18456, Severity: 14, State: 38”。
如果将连接字符串中的 “User id” 更改为 “dbo”,则会报告以下错误:“Login failed for user 'dbo'. Reason: Could not find a login matching the name provided. [Client: xxx.xxx.x.xx]”。
我的 ASP.NET 应用程序尝试连接时才出现此问题。使用 SQL Server Management Studio Express 和上述凭据登录是可行的。
1. 使用 SQL Server Management Studio Express 登录并创建一个新登录。 2. 使用新创建的登录作为所有者创建了一个新数据库。
如最后一张截图所示,“dbo” 是属于“mylogin” 登录名的“用户名”。我试图使用以下连接字符串连接,但它不起作用:
Data Source=(local)\sqlexpress;Initial Catalog=newdb;User id=mylogin;Password=mypass
在 SQL Server Management studio express 的错误日志中显示:“Login failed for user 'mylogin'. Reason: Failed to open the explicitly specified database. [CLIENT: xxx.xxx.x.xx]. Error: 18456, Severity: 14, State: 38”。
如果将连接字符串中的 “User id” 更改为 “dbo”,则会报告以下错误:“Login failed for user 'dbo'. Reason: Could not find a login matching the name provided. [Client: xxx.xxx.x.xx]”。
我的 ASP.NET 应用程序尝试连接时才出现此问题。使用 SQL Server Management Studio Express 和上述凭据登录是可行的。
SELECT @@SERVERNAME
返回什么?如果它与你尝试从ASP.NET连接到的不同,那就太糟糕了。 - Aaron Bertrand