Search This Blog


Friday, September 12, 2008

"Cannot open user default database" error in Visual Studio

I've encountered a very, very weird problem when I tried to open my SQL server database in Visual Studio 2008. Here's the description:

  1. When I clicked on my database (mydb.mdf) in Visual Studio's server explorer, I encountered this error: System.Data.SqlClient.SqlException: Cannot open user default database. Login failed.
    Login failed for user 'ComputerName\LoginAccount'
  2. If I opened my SQL Server Management Studio Express, I can see the mydb.mdf. If I clicked on it, then I could see all the tables and columns. No opening error.
The solution was deceptively simple. You just have to drop the mydb.mdf in the SQL Server Management Studio. To do this, click on the mydb.mdf, right-clicked on it, choose Task->Detach.
    Now try to click on the mydb in VS, you should be able to get it open.
    Curse M$ for not making the error more explicit!

    1 comment:

    Anonymous said...

    It worked.Cheers