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

4

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)
sql-server
sharing
mdf
asked on Stack Overflow Feb 1, 2012 by Suzan Cioc • edited Nov 4, 2012 by surfmuggle

3 Answers

0

MDF files are not intended to be used directly.

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

answered on Stack Overflow Feb 1, 2012 by Oleg Dok • edited Jun 27, 2013 by hyde
0

Try this:

1- Create a database with the same name to mdf file.

2- Stop sql service

3- Go to the Data Carpet where is all mdf files and ldf , copy your original mdf file y replace.

4- Start the service

5- See in the management studio if the database still online there you go.

answered on Stack Overflow Apr 27, 2019 by Alejandro Castillo • edited Apr 27, 2019 by Avi
-1

A .MDF database cannot be "opened".

It must be attached to an existing (and running) SQL Server instance.

If you have SQL Server Management Studio running, open a connection, and right click on databases. Choose "Attach" and point to the .MDF file. This will (attempt to) attach the database to the master database. If it works, the database will be visible in SSMS.

answered on Stack Overflow Feb 1, 2012 by aF.

User contributions licensed under CC BY-SA 3.0