Can't connect to my own MDF file. Cannot open user default database. Login failed.Login failed for user... and other errors

Suzan Cioc picture Suzan Cioc · Feb 1, 2012 · Viewed 15.9k times · Source

SQLSEXPRESS service IS running!!

I have I program I wrote some time ago and it works. It was written in MS Visual Studio with local MDF file.

How is it possible to edit this file from Microsoft SQL Server Management Studio? I don't see this file in the list of globally connected databases.

If I try to attach this file with Visual Studio Wizard, I get message that such database already exists, but when I set arbitrary logical name, I get sharing violation.

How to reach MDF file?

EDIT 1

Now I found that my program also stopped to work.

The summary of results of different attempts to reach MDF file:

  1. Program itself System.Data.SqlClient.SqlException (0x80131904): Cannot open user default database. Login failed. Login failed for user <username>. (windows user)
  2. Visual Studio, Data source = Microsoft SQL Server, Logical Name = "" Error message: An attempt to attach an auto-named database for file <filename> failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
  3. Visual Studio, Data source = Microsoft SQL Server, Logical Name = SOMENAME Error message Unable to open the physical file <filename>. Operating system error 32: "32(The process cannot access the file because it is being used by another process )". Cannot attach the file <filename> as database ‘SOMENAME’.
  4. Visual Studio, Data source = Microsoft SQL Server Database File, Windows Authentication Error message: Cannot open user default database. Login failed. Login failed for user <username>.
  5. Visual Studio, Data source = Microsoft SQL Server Database File, SQL Server Authentication Error message: Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed.
  6. Microsoft SQL Server Management Studio, Attach Database Error message: Unable to open the physical file <filename>. Operating system error 32: "32(The process cannot access the file because it is being used by another process)". (Microsoft SQL Server, Error: 5120)

Answer

Oleg Dok picture Oleg Dok · Feb 1, 2012

MDF files are not intended to be used directly.

You may use them only through and with the help of SQL Server Engine.