“无法打开用户默认数据库。登录失败。后安装SQL Server Management Studio Express [英] "Cannot open user default database. Login failed." after installing SQL Server Management Studio Express

查看:557
本文介绍了“无法打开用户默认数据库。登录失败。后安装SQL Server Management Studio Express的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在程序使用的本地文件中有一个数据库。该程序的功能有限,我需要运行一些快速查询。我安装了SQL Server Management Studio Express 2005(SSMSE),连接到SQL Server实例,附加了数据库文件,并运行查询。现在原始程序将不再连接到数据库。我收到错误:

I have a database in a local file that is used by a program. The program has limited functionality and I needed to run some quick queries. I installed SQL Server Management Studio Express 2005 (SSMSE), connected to the SQL Server instance, attached the database file, and ran the queries. Now the original program will no longer connect to the database. I receive the error:


无法打开用户默认数据库。登录失败。用户'MyComputer \MyUserName'的登录失败。

Cannot open user default database. Login failed. Login failed for user 'MyComputer\MyUserName'.

我回到SSMSE并尝试设置默认数据库。我已打开安全,登录,BUILTIN \管理员 BUILTIN\Users 。在常规下,我将默认数据库设置为程序的数据库。在用户映射下,我确保选中了数据库,并选中了 db_datareader db_datawriter

I've gone back into SSMSE and tried to set the default database. I've opened up Security, Logins, BUILTIN\Administrators and BUILTIN\Users. Under General, I have set the default database to the program's database. Under User Mappings, I made sure the database is ticked and that db_datareader and db_datawriter are ticked.

程序使用连接字符串:


服务器=(本地)\实例; AttachDbFilename = C:\PathToDatabase\Database.mdf;集成安全= True; User Instance = True;

Server=(local)\Instance; AttachDbFilename=C:\PathToDatabase\Database.mdf; Integrated Security=True; User Instance=True;

我知道jack-all关于数据库管理。

I know jack-all about database administration. What else am I missing?

推荐答案

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

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.

这篇关于“无法打开用户默认数据库。登录失败。后安装SQL Server Management Studio Express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆