现有用户SQL Server 2012登录失败

Login Failed for existing user SQL Server 2012
2021-06-20
  •  译文(汉语)
  •  原文(英语)

使用C#,我尝试从Visual Studio 2012连接到SQL Server 2012中的现有数据库.我使用Visual Studio向导获取我的连接字符串,并告诉它使用Windows身份验证(我在SQL中使用的身份) DB,在我的系统上本地托管).这是我得到的错误:

Cannot open database "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQ\DATA
\StockHolesDB.mdf" requested by the login. The Login failed.
Login failed for user '***\***'.

我的连接字符串是 "Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"C:\\Program Files\\Microsoft SQL Server\\MSSQL11.MSSQLSERVER\\MSSQL\\DATA\\StockHolesDB.mdf\";Integrated Security=True;Connect Timeout=30"

在线浏览时,我看到解决方案之一是在sql服务器中设置该用户.但是,用户在服务器中已经建立.用户名不同,但登录名相同.当我尝试添加具有相同登录名但用户名不同的新用户时,它将不起作用.

编辑:我试图更改数据库名称,并且也没有用.

解决过程1

确保已在MSSQL上启用"SQL Server和Windows身份验证模式"(在服务器上的"安全性"选项卡下,右键单击)

Using C# I'm trying to connect to an existing DB in SQL Server 2012, from Visual Studio 2012. I used the Visual Studio wizard to get my connection string, and I told it to use Windows Authentication (what I am using for my SQL DB, hosted locally on my system). This is the error I get:

Cannot open database "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQ\DATA
\StockHolesDB.mdf" requested by the login. The Login failed.
Login failed for user '***\***'.

My connection string is "Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"C:\\Program Files\\Microsoft SQL Server\\MSSQL11.MSSQLSERVER\\MSSQL\\DATA\\StockHolesDB.mdf\";Integrated Security=True;Connect Timeout=30"

Looking around online I saw that one of the solutions is to set that user up in the sql server. But that user is already set up in the server. A different username, but the same login name. And when I tried to add a new user with the same login name but different username it wouldn't work.

EDIT: I tried changing the DB name, and that didn't work either.

Solutions1

Make sure you enabled 'SQL Server and Windows Authentication mode' on MSSQL (right click on server, under security tab)

转载于:https://stackoverflow.com/questions/18571747/login-failed-for-existing-user-sql-server-2012

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入