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

最后都变了- 提交于 2020-01-13 03:51:09

问题


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)

回答1:


MDF files are not intended to be used directly.

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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/9093458/cant-connect-to-my-own-mdf-file-cannot-open-user-default-database-login-faile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!