4

I have a database which is sitting 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 SQL Server Management Studio and run queries against it?

But I want to create .mdf file based on existing database which will save me time on rebuilding whole DB in Visual Studio and also it will have all of the data in tables.

I check this link. it is not helping me solve my question.

Also was trying to copy .mdf file from C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA into my project in App_Data folder but it trowing error cannot complete because file is used by SQL Server
Thank you.

Sathish
  • 1,936
  • 4
  • 28
  • 38
Andrey
  • 1,629
  • 13
  • 37
  • 65
  • 1
    is it a big database? Before copying, make shure database connections are closed (alse close visual studio) – lordkain Aug 15 '13 at 05:33
  • yes DB is big more that 100K records. I just stop db in Management studio after that i was able to copy it in `App_Data` folder in my project – Andrey Aug 15 '13 at 18:05
  • 2
    possible duplicate of [SQL - How to backup a database and export as a MDF file with MS SQL 2008 R2](http://stackoverflow.com/questions/3971727/sql-how-to-backup-a-database-and-export-as-a-mdf-file-with-ms-sql-2008-r2) – mo5470 Dec 16 '13 at 10:30
  • 3
    This question has been answered: http://stackoverflow.com/questions/3971727/sql-how-to-backup-a-database-and-export-as-a-mdf-file-with-ms-sql-2008-r2 – mo5470 Dec 16 '13 at 10:30

1 Answers1

1

First close all the programs and then stop the SQL SERVER AGENT. You should now be able to copy the .mdf file. After copying the files, don't forget to start the SQL SERVER AGENT.

Sushil
  • 196
  • 1
  • 8