Home > other >  attach a database to Azure data studio
attach a database to Azure data studio

Time:01-23

I am running Azura data studio on docker on my Mac, and have a server running, in which I need to attach a database to that I have locally in .mdf format. I have tried right clicking to click attach database as you would in sql server express, but it isn't working, nothing shows up when I right click but refresh.

I have also tried running this SQL query:

CREATE DATABASE myDB ON 
(FILENAME = './databasesLocal/mydb.mdf'),
(FILENAME = './databasesLocal/mydb.ldf') 
FOR ATTACH;

but when I do this, I get this error:

Msg 5105, Level 16, State 2, Line 1
A file activation error occurred. The physical file name './databasesLocal/mydb.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation.

does anyone know what I can do to attach a database?

CodePudding user response:

I tried to attach database with below code:

CREATE  DATABASE  myDB1
ON (FILENAME  =  '.DATA\db.mdf'),
(FILENAME  =  '.DATA\db.ldf')
FOR ATTACH;

I got below error:

enter image description here

I tried with below code:

 CREATE  DATABASE  myDB1
    ON (FILENAME  =  'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\db.mdf'), 
    (FILENAME  =  'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\db.ldf')
    FOR ATTACH;

Command run successfully

enter image description here

Database created successfully.

enter image description here

Once check your file path properly. Give the whole path file. Even if you have whitespace in path, you will get the error. Along with that check your folder permission.

  • Related