且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“无法打开用户默认数据库。登录失败。后安装SQL Server Management Studio Express

更新时间:2022-02-20 22:38:44

首先,尝试隔离您的问题:

First, try to isolate your problem:


  1. 备份文件!

  2. 您确定通过Management Studio连接到同一个实例,该程序是?
  3. >
  4. 如果可能,请尝试关闭您不希望使用的实例。

  5. 将用户的默认数据库设置为master并尝试让程序登录

  6. 尝试通过Management Studio以用户身份登录 - 由于您已集成安全性,因此您应该以该计划的用户身份打开Management Studio。

  7. 你使用用户实例 - 也许不知道吗?如果是这样,这可能会有所帮助: http://blogs.msdn.com/b/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio .aspx

  1. Take a backup of the file! Some of the steps below can, apparently, in some circumstances cause the file to vanish.
  2. Are you sure you are connecting to the same instance through Management Studio as the program is?
  3. If possible, try to shut down the instance that you are not expecting to use.
  4. Set the user's default database to master and try to make the program logon.
  5. Try to login as the user through Management Studio - since you have integrated security, you should open Management Studio as the program's user.
  6. Are you using "User instances" - perhaps without knowing it? If so, this may be helpful: http://blogs.msdn.com/b/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx

我没有像你的程序那样使用附加的文件。您还在Management Studio中附加了数据库。你在运行你的程序之前试过分离它吗?也许你看到管理工作室和你的程序竞争的独家访问MDF文件?

I haven't worked much with files being attached in the way your program does - but you write that you attached the DB in the Management Studio as well. Have you tried detaching it there before running your program? Perhaps you are seeing the Management Studio and your program competing for exclusive access to the MDF-file?

编辑:我添加了上面的点6 - 这是在我自己的列表的TODO在排除此类型的登录失败时。但它听起来很像你遇到的。

I added point 6 above - this is new in my own list of TODOs when troubleshooting this type of Login failed. But it does sound a lot like what you're experiencing.

EDIT2:在第一次编辑,新项目被添加到列表中。因此,评论中的数字与答案中的数字不一致。

In the first edit, new item was added to the list. So the numbers in the comments doesn't correspond with the numbers in the answer.