1

I get a trouble when I trying to connect to my database (using SQL Server). I make a small sale manager application. So in tables to input, remove, repair,... I create connect via design, so I just drag and drop it (datagridview, textbox to input, etc...) into my form. But when I make a filter form, I create a connect with connection string like this: "Server=.\SQLEXPRESS; AttachDbFileName=" + Application.StartupPath + "\\" + "QLBH.mdf; Trusted_Connection=Yes; User Instance=True";. With the same mdf file in current folder of program. When I debug my program, I just use one in two connections. I get an error messager box cannot open user default database. login failed!. What I have to do to fix this bug? Thanks

Ralt
  • 2,084
  • 1
  • 26
  • 38
Ryan can fly
  • 123
  • 1
  • 11
  • its not a bug. its a security problem in terms of your database and user accounts for the SQL Instance. This is something you need to check that your current user account has access to the instance and can access the database in question. – Ahmed ilyas Oct 29 '14 at 15:35
  • Check out the following site. http://www.connectionstrings.com/sql-server-2012/ – neo Oct 29 '14 at 15:38
  • @Ahmedilyas hello, thanks for your quick reply! I think my problem due to I make 2 connections to 1 database file. I think it's not about security, because I had checked it in my mdf and ldf files – Ryan can fly Oct 29 '14 at 15:43
  • @neo Hello! My connection string works fine. But I just only use 1 in both connection, conection string or connection via design.When I use one in both, the extant one I can't use with the problem I told above – Ryan can fly Oct 29 '14 at 15:46
  • it will be a security issue hence the "login failed" message. That is part of security :) any reason why you are using 2 connections at a time? – Ahmed ilyas Oct 29 '14 at 15:48

1 Answers1

1

The user default database is unavailable at the time of connection. It is possible that the database:

  • Is in suspect mode.
  • No longer exists.
  • Is in single user mode and the only available connection is already being used by someone else or by something else.
  • Has been detached.
  • Has been set to the RESTRICTED_USER state.
  • Is offline.
  • Is set to emergency status.
  • Does not have the login account mapped to a user or the user has been denied access.
  • Is part of a database mirror.

Additionally, the login account may be a member of multiple groups and the default database for one of those groups is unavailable at the time of connection.

Reference: http://support.microsoft.com/kb/307864 Related Question: "Cannot open user default database. Login failed." after installing SQL Server Management Studio Express

Community
  • 1
  • 1