2

I am running Microsoft SQL Server on Linux for Docker Engine which I am accessing through an OSX host machine using mssql-cli.

I am trying to attach an existing database for which I have the .mdf and .ldf files.

However, when I run the command

CREATE DATABASE MyDb  
    ON (FILENAME = '/path/to/MyDb.mdf'),   
    (FILENAME = '/path/to/MyDbLogs.ldf')   
    FOR ATTACH;  

I get the error:

Unable to open the physical file "/path/to/MyDb.mdf". Operating system error 2: "2(The system cannot find the file specified.)".

I have verified the file does exist at that location on the host machine e.g.

$ test -e /path/to/MyDb.mdf && echo file exists || echo file not found
file exists

I also attempted mounting the folder containing the DB in the docker container in case it is looking for it in there but in this case I get the error:

Unable to open the physical file "/app/path/to/MyDb.mdf". Operating system error 87: "87(The parameter is incorrect.)".

Any idea what is causing these errors given I have verified the file is at the location, is there something special about file paths when using OSX or Microsoft SQL Server on Linux for Docker Engine?

1
  • 1
    Does the account that the SQL Server Agent is running under have permissions to the location above?
    – Ross Bush
    Aug 14, 2019 at 13:44

2 Answers 2

1

OK I figured this out now, the missing step was that the backup files need to the copied into the Docker container.

e.g.

docker exec -it containerName mkdir /var/opt/mssql/backup

docker exec -it containerName cp /local/path/to/files containerName:/var/opt/mssql/backup

Then once connected to the database run the query pointing to the paths in the container e.g.

CREATE DATABASE MyDb  
    ON (FILENAME = '/var/opt/mssql/backup/MyDb.mdf'),   
    (FILENAME = '/var/opt/mssql/backup/MyDbLogs.ldf')   
    FOR ATTACH;  
0

I had the same problem and searching about the problem, found a solution: do the same but without the *.ldf file. Like this:

CREATE DATABASE NewDb
    ON (FILENAME = '/var/opt/mssql/data/Olddb.mdf')
    FOR ATTACH;

I'm using Azure Data Studio for Linux Ubuntu 18.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.