[英]Connection string “Login failed for user”
I'm trying to connect to my database using the following connection string: 我正在尝试使用以下连接字符串连接到我的数据库:
Data Source=LORDKANELSNEGLE\SQLEXPRESS;AttachDbFilename="C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\Database.mdf";Integrated Security=True;MultipleActiveResultSets=True
However, this gives me the error Login failed for user "LORDKANELSNEGLE\\Lord Kanelsnegle"
, despite me being able to login with those exact credentials in SSMS as shown here. 但是,这给了我错误消息Login failed for user "LORDKANELSNEGLE\\Lord Kanelsnegle"
,尽管我能够使用SSMS中的确切凭据登录,如下所示。
I've even tried adding the login from the Security tab within SSMS and received this error, 我什至尝试从SSMS的“安全性”选项卡添加登录名,并收到此错误,
confirming that this login does in fact already exist (as if me logging in with them wasn't evidence enough). 确认此登录实际上确实已经存在(好像我没有足够的证据登录)。
I've read every other post, stackoverflow or other, that I could find regarding failed Windows Authentication logins for SQL Server but none of the solutions worked for me. 我读过所有其他文章,stackoverflow或其他文章,这些文章我都可以找到有关SQL Server Windows身份验证登录失败的信息,但是没有一种解决方案适合我。 Ideas? 想法?
You should remove AttachDbFilename="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.SQLEXPRESS\\MSSQL\\DATA\\Database.mdf
from your connection string. 您应该从连接字符串中删除AttachDbFilename="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.SQLEXPRESS\\MSSQL\\DATA\\Database.mdf
。
You don't use localdb
but fully functional Express Edition
. 您不使用localdb
而是使用功能齐全的Express Edition
。
I imagine that your database is permanently attached to the instance and there is no need to re-attach it. 我想象您的数据库永久地附加到实例,而无需重新附加它。 So I think if you look in your SQL Server error log
you'll see the error saying that it was impossible to attach that database because it's already attached and it was the reason of login failure. 因此,我认为,如果您查看SQL Server error log
,则会看到错误消息,指出不可能附加该数据库,因为该数据库已经附加,这是登录失败的原因。
Another reason can be that your login is not mapped to that database. 另一个原因可能是您的登录名未映射到该数据库。 In this case unless it's sysadmin it cannot enter the database. 在这种情况下,除非是sysadmin,否则它无法进入数据库。 And this reason is also reported in error log
. 并且此原因也在error log
报告。 Server does not write the reason to the user in login failed
error for security reasons but any sysadmin can find it in error log next to 18456 error 服务器出于安全原因login failed
在login failed
错误中向用户写入原因,但是任何系统管理员都可以在错误日志中找到18456错误旁边的原因
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.