Search code examples
asp.net-mvcsql-server-expresscassini

Making a copy of an ASP.NET MVC website on the same machine - catastrophy?


I wanted to run (using Cassini) two copies of my web application from the same computer - not unreasonable (or so I thought!). One using port 80, the other using port 81. So I did the following:

  1. Stopped Cassini and SQL Express
  2. Copy and paste of the site root folder (and renamed it)
  3. Opened Cassini explorer and setup a new site on port 81 and pointed it to the copied location
  4. Changed the web.config of the copied site so that the connection string used "Database=NewAlias" because SQL Express cant attach two databases with the same alias.
  5. Started Cassini and SQL Express again

When I browsed to the NEW site, the first thing that comes up is:

Unable to open the physical file "C:\site1\App_Data\db_log.ldf". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)". Cannot create file 'C:\site2 \App_Data\db_log.LDF' because it already exists. Change the file path or the file name, and retry the operation. Cannot open database "NewAlias" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\SYSTEM'. File activation failure. The physical file name "C:\site1\App_Data\db_log.ldf" may be incorrect.

Its trying to open the mdf from the OLD location (even if the web.config specifies the exact mdb path to the new location) but trying to create a log in the NEW location. Then to top it all off, drops the hint that it cannot access the ldf from the OLD location, or maybe cant log into it.

Well done Microsoft and your team once again for some truly intuitive errors! Can anyone help?


Solution

  • I don't think you can just copy a live database via the files. If you detach it first, then copy it, you can then reattach (with sp_detach_db) it by mounting the files as a new database.

    sp_detach_db OldDb
    

    Then copy the folder, then reattach (with sp_attach_db) the db files as a new database.

    sp_attach_db NewDb, "C:\copy of site\App_Data\db_data.mdf", "C:\site1\App_Data\db_log.ldf"