How to create a .MDF file based on an existing database in SQL Server?

I have a database that sits on my local PC. I want to create a .mdf file based on this database. I created an empty .mdf file in Visual Studio. How to connect to SQL Server Management Studio and run queries against it?

But I want to create a .mdf file .mdf on an existing database, which will save me time on restoring the entire database in Visual Studio, and will also have all the data in the tables.

I check this link. this does not help me solve my question.

Also tried to copy the .mdf file from C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA to my project in the App_Data folder, but it ran an error App_Data cannot complete because file is used by SQL Server
Thanks.

+4
source share
1 answer

Close all programs first, and then stop SQL SERVER AGENT. Now you can copy the .mdf file. After copying the files, remember to run SQL SERVER AGENT.

0
source

Source: https://habr.com/ru/post/1497167/


All Articles