SqlServer AttachDbFilename on Mac docker sql instance

KK 191 Reputation points
2022-07-10T14:49:55.987+00:00

Hi team,

I am migrating a project from windows to mac.
A sql server instance has been created and running in a docker on mac.

Tested connecting and mssql login without any problems.

My project is an asp.net core web project with a DB connectionStrings where I put like this.

"DBstr" : "Server=localhost;Initial Catalog=Repos;AttachDbFilename=/Users/TestUser/repos/project_name/App_data/repos.mdf;User Id=sa;Password=**comm1234;TrustServerCertificate=true;Connect Timeout=30"

Then when I run the project in Visual Studio, it thrown an error with info as below.

Unable to open the physical file "/Users/TestUser/repos/project_name/App_data/repos.mdf". Operating system error 2: "2(The system cannot find the file specified.)".
Cannot attach the file '/Users/TestUser/repos/project_name/App_data/repos.mdf' as database 'Repos'.

The path is definitely correct. I am not sure if sql server supports this kind of attaching operation? Can somone help explain please?

Thanks.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,310 questions
0 comments No comments
{count} votes

Accepted answer
  1. YufeiShao-msft 7,131 Reputation points
    2022-07-11T06:21:23.17+00:00

    Hi @KunLi-4284,

    Please make sure your SQL Server account have the permission to read and write data file

    And for local db, you can try to drop the Initial Catalog property

    Referring to this thread:
    https://stackoverflow.com/questions/17012839/cannot-attach-the-file-mdf-as-database/20176660#20176660

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

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. KK 191 Reputation points
    2022-07-11T06:41:29.537+00:00

    Hi Yufeishao-msft,

    Thanks for the reply.

    I am using 'sa' as login user, I think it should have all permissions as sysadmin? And since this sql server instance is running on Mac within docker, not sure if Sql Server support the mdf file attachment with cross platform?


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.