Core 6 .mdf not opening in MSSMS

Dean Everhart 1,541 Reputation points
2022-11-13T18:21:35.96+00:00

Problem Description

brand new Core 6 project with simple database with two records (property sets) added to it using SQLExpress.

MSSMS unable to open .mdf file throwing errors (error log below).

Steps Taken So Far:

Verified full access to .mdf file to user accounts on computer.

Error:

TITLE: Microsoft SQL Server Management Studio

------------------------------

Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)

For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476

------------------------------

ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

CREATE FILE encountered operating system error 2(The system cannot find the file specified.) while attempting to open or create the physical file 'C:\Users\User1\WebApplicationProjectLevel.Data'. (Microsoft SQL Server, Error: 5123)

For help, click: https://learn.microsoft.com/sql/relational-databases/errors-events/mssqlserver-5123-database-engine-error

------------------------------

BUTTONS:

OK

------------------------------

SQL Server | Other
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 78,086 Reputation points Volunteer Moderator
    2022-11-14T17:43:54.487+00:00

    you connect to server: (localdb)\mssqllocaldb

    then you will need to attach the database if it is not attached.

    https://learn.microsoft.com/en-us/sql/relational-databases/databases/attach-a-database?view=sql-server-ver16

    note: you will need the full file path to the .mdf


2 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,086 Reputation points Volunteer Moderator
    2022-11-13T18:54:49.083+00:00

    Use the same connection string with studio as in the .net 6 project. It should be able to connect to sql express the same way.

    Note: SSMS can not open a mdf directly, it needs a sql service instance to attach and expose it. The connect string gives the instance the info to attach.


  2. Dean Everhart 1,541 Reputation points
    2022-11-19T20:15:26.673+00:00

    Problem resolved.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.