Search code examples
asp.netvisual-studio-2008sql-server-2005mdfappdata

How do I copy a DB from the server to the application's AppData folder?


I've been working on an ASP.NET application accessing a DB in my local machine. Now I want to have this DB in the app's AppData folder instead, so I can easily work on it from within VS SQL instance accessing the mdf file, and easily copy and share it between programmers.

Thanks a lot!


Solution

  • First, use SSMS to detach your database.

    Next, find the MDF and LDF files for your database. They should be in:

    C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
    

    Copy those files to your App_Data folder.

    If you want to switch to using SQL Express, then change your connection string to point to the MDF file. If you want to continue using SQL Developer / etc, then use SSMS to re-attach the MDF and LDF from their new location.

    I guess I should add that this usually isn't a good idea, but I assume you have your reasons.