开发者

Cannot open database "test" requested by the login. The login failed

I'm failing this for the quadrizillionth time and I understand I will never become a dba.

  • I've just re开发者_运维问答stored a database to my local server running SQL Express into "test".
  • I've mapped my local db user "testuser" to the database as db_owner
  • Sql server express is running mixed mode authentication
  • I'm trying to connect to the database using the following connection string:

    "Data Source=(local)\sqlexpress;User Id=testuser;Password=supersecret;Initial Catalog=test;"

Can somebody please tell me what I'm missing here?


It's possible you have an orphaned user. What does this yield?

SELECT 
    dp.name, 
    sp.name 
FROM
    sys.database_principals AS dp
FULL OUTER JOIN
    sys.server_principals AS sp
    ON dp.[sid] = sp.[sid]
WHERE 
    dp.name = 'testuser';

Basically if your database user "testuser" is not mapped correctly to the login of the same name, the server will have no way to connect you to the right database. You can see the following article for troubleshooting help:

http://msdn.microsoft.com/en-us/library/ms175475%28SQL.100%29.aspx


Ensure that TCP/IP protocol is enabled (in SQL Server Configuration Manager). Also ensure that SQL Browser service is enabled, started, and automatic (in SSCM as well). By default these two things for SQL Server Express are not initially configured/started as such.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜