Database Copying Wizardry

AID: 7251
  • Status: Published

3200 points

  • By
  • TypeTutorial
  • Posted on2011-08-25 at 00:46:57
Introduced in Microsoft SQL Server 2005, the Copy Database Wizard is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool. Another possible usage is to create a database replica on a development machine, which is exactly what tuchfeld wanted to do in the "Copy Microsoft SQL Server 2008 DB..." question I recently participated in. As a result of this question, I wanted to share a quick how-to guide, so here we are and off we go...

To start, launch the Copy Database Wizard via Tasks | Copy Database...

Servers and Settings


1. Set Source Server, which can be an instance running SQL Server 2000 or higher; click Next.
CDW-01-Source.png
  • 79 KB
  • Figure 1
Figure 1

Note: this screen defaults to Windows Authentication; however, please ensure to choose the appropriate Authentication method based on your configuration. Remember, per Microsoft's documentation, you MUST be a sysadmin on both servers.

2. Set Destination Server, which must be running SQL Server 2005 Service Pack 2 at a minimum; click Next. Note: the target server requires the SQL Server Agent feature, so SQL Express will not work. As of the writing of this Article, this includes SQL Server Code-Named "Denali" Express Edition, despite the installation with Advanced Services loading a SQL Server Agent Service.
CDW-02a-Destination.png
  • 80 KB
  • Figure 2a
Figure 2a

Note: this screen also defaults to Windows Authentication; therefore, as before, please choose the Authentication method corresponding to your sysadmin credentials.

If SQL Server Agent is not started on destination server, you will get the prompt depicted by 'Figure 2b' as a reminder. Note: you can proceed without starting the Agent Service; however, the copy will FAIL as illustrated by 'Figure 10a' and 'Figure 10b'.
CDW-02b-SQLAgent.png
  • 22 KB
  • Figure 2b
Figure 2b

If you choose a SQL Express instance as a target, you will get the following message box.
CDW-02c-NoExpress.png
  • 22 KB
  • Figure 2c
Figure 2c

3. Choose Transfer Method; click Next. Detach and Attach method is fastest, but SQL Server Management Objects (SMO) method is handy for copying databases that needs to remain usable. Note: Microsoft recommends Detach and Attach for 64-bit SQL Server 2005 systems.
CDW-03a-OfflineMethod.png
  • 124 KB
  • Figure 3a
Figure 3a
CDW-03b-OnlineMethod.png
  • 109 KB
  • Figure 3b
Figure 3b


Databases and Dependencies


4. Select Databases to copy or move, noting system databases (i.e., model, msdb and master) cannot be transferred using this tool; click Next.
CDW-04-Databases.png
  • 99 KB
  • Figure 4
Figure 4

5. Configure New Databases, assigning appropriate file locations and choosing how conflicts are handled; click Next.
CDW-05-NewDatabases.png
  • 159 KB
  • Figure 5
Figure 5

6. Select Additional Objects, e.g., Logins, to transfer; click Next. Note: the master database itself may not be transferable, but shared stored procedures from master can be using this dialog.
CDW-06-Objects.png
  • 90 KB
  • Figure 6
Figure 6


Package and Plan


7. Name SSIS Package, which will be reflected in the created SQL Agent job; click Next. Optionally, you can set "Windows event log" or "Text file" logging and, for the latter, an "Error log file path" value.
CDW-07-Package.png
  • 95 KB
  • Figure 7
Figure 7

8. Plan SSIS Package execution time, either immediate or scheduled; click Next.
CDW-08a-Schedule.png
  • 90 KB
  • Figure 8a
Figure 8a

If schedule is selected, then SQL job schedule dialog like 'Figure 8b' is available to set execution time for transfer.
CDW-08a-ScheduleDialog.png
  • 107 KB
  • Figure 8b
Figure 8b


Wrap-up and Wait


9. Verify Details; click Finish.
CDW-09-Verify.png
  • 146 KB
  • Figure 9
Figure 9

10. Examine Results.

If you clicked "Yes" through the SQL Server Agent ('Figure 2b') warning discussed earlier, the result is an error message box similar to 'Figure 10b'.

If the SQL Server Agent Service is started, then the first four checks should pass.

Subsequently, because the SSIS package is executed as a single job step, any errors during the process big or small will cause the job to fail, resulting in an error on step five similar to 'Figure 10d' depending on your logging option.
CDW-10d-JobFailed.png
  • 21 KB
  • Figure 10d
Figure 10d

For purposes of this Article I set logging to the Windows Event Log; therefore, as stated, errors are found by going to Event Viewer on the destination server. Just remember, do not panic. As I said, not every error is fatal. For example you may experience Event ID 12550 -- error caused by the destination server trying to run "EXEC dbo.sp_changedbowner" that fails with message "Cannot find the principal '{source server login}', because it does not exist or you do not have permission." Though, the job indicates failure, you will find the database successfully copies in instances such as this.

Conclusion


Hopefully this Article was helpful for you in some fashion. As a recap, the Copy Database Wizard is a handy tool for System Administrators to move or copy databases and associated objects from one Microsoft SQL server instance to another, leveraging the SQL Server Management Object capabilities (optional), SQL Server Integration Services packages, and SQL Server Agent jobs. Like other tools in your SQL tool belt, I wish CDW serves you well.

Thank you very much for reading...

Best regards and happy coding,

Kevin C. Cross, Sr. (mwvisa1)


References


Related Q&A
http://www.experts-exchange.com/Q_27273894.html

Related SQL Server Documentation
http://msdn.microsoft.com/en-us/library/ms188664.aspx
http://msdn.microsoft.com/en-us/library/cc645993.aspx

Resources
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=9969


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If you found this article helpful, please click the Yes button after the question just below. This will give me (the author) a few points and might encourage me to write more articles.

If you didn't or otherwise feel the need to vote No, please first leave a comment to give me a chance to answer and perhaps to improve this article.

Thank you!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Asked On
    2011-08-25 at 00:46:57ID7251
    Tags

    MS SQL Server

    ,

    Copy Database Wizard

    ,

    copy

    ,

    database

    ,

    objects

    ,

    detach

    ,

    attach

    ,

    SMO

    ,

    SSIS

    Topic

    MS SQL Server

    Views
    1297

    Comments

    Expert Comment

    by: skrile on 2011-08-28 at 06:37:37ID: 30961

    I have no idea how this feature has escaped me for so long.  Thanks for the article.

    Author Comment

    by: mwvisa1 on 2011-08-28 at 07:59:34ID: 30962

    Thanks for reading and voting, skrile! I am just glad it has helped.
    Regards, Kevin

    Author Comment

    by: mwvisa1 on 2012-01-21 at 06:35:53ID: 34675

    Here is a potentially interesting T-SQL scripted approach to detaching/attaching all databases using sysdatabases and sysaltfiles to dynamically build  sp_detach_db and sp_attach_db procedure calls.

    Add your Comment

    Please Sign up or Log in to comment on this article.

    Join Experts Exchange Today

    Gain Access to all our Tech Resources

    Get personalized answers

    Ask unlimited questions

    Access Proven Solutions

    Search 3.2 million solutions

    Read In-Depth How-To Guides

    1000+ articles, demos, & tips

    Watch Step by Step Tutorials

    Learn direct from top tech pros

    And Much More!

    Your complete tech resource

    See Plans and Pricing

    30-day free trial. Register in 60 seconds.

    Loading Advertisement...

    Top MS SQL Server Experts

    1. jogos

      246,566

      Guru

      1,668 points yesterday

      Profile
      Rank: Sage
    2. acperkins

      246,249

      Guru

      1,000 points yesterday

      Profile
      Rank: Genius
    3. lcohan

      194,990

      Guru

      2,000 points yesterday

      Profile
      Rank: Genius
    4. anujnb

      179,525

      Guru

      2,000 points yesterday

      Profile
      Rank: Wizard
    5. ScottPletcher

      154,405

      Guru

      6,500 points yesterday

      Profile
      Rank: Genius
    6. matthewspatrick

      131,392

      Master

      1,620 points yesterday

      Profile
      Rank: Savant
    7. ValentinoV

      126,429

      Master

      1,800 points yesterday

      Profile
      Rank: Genius
    8. EugeneZ

      120,790

      Master

      2,000 points yesterday

      Profile
      Rank: Genius
    9. TempDBA

      112,141

      Master

      1,168 points yesterday

      Profile
      Rank: Sage
    10. angelIII

      100,133

      Master

      0 points yesterday

      Profile
      Rank: Elite
    11. HainKurt

      93,046

      Master

      0 points yesterday

      Profile
      Rank: Genius
    12. mwvisa1

      88,585

      Master

      40 points yesterday

      Profile
      Rank: Genius
    13. dtodd

      88,114

      Master

      0 points yesterday

      Profile
      Rank: Genius
    14. huslayer

      81,392

      Master

      0 points yesterday

      Profile
      Rank: Sage
    15. ralmada

      75,583

      Master

      400 points yesterday

      Profile
      Rank: Genius
    16. BCUNNEY

      74,206

      Master

      0 points yesterday

      Profile
      Rank: Guru
    17. dqmq

      66,272

      Master

      0 points yesterday

      Profile
      Rank: Genius
    18. rajeevnandanmishra

      60,246

      Master

      2,000 points yesterday

      Profile
      Rank: Guru
    19. dbaduck

      58,208

      Master

      2,000 points yesterday

      Profile
      Rank: Sage
    20. CodeCruiser

      55,120

      Master

      0 points yesterday

      Profile
      Rank: Genius
    21. Qlemo

      53,598

      Master

      2,000 points yesterday

      Profile
      Rank: Genius
    22. ryanmccauley

      52,252

      Master

      0 points yesterday

      Profile
      Rank: Sage
    23. Cluskitt

      50,880

      Master

      800 points yesterday

      Profile
      Rank: Wizard
    24. sdstuber

      50,836

      Master

      0 points yesterday

      Profile
      Rank: Genius
    25. mark_wills

      49,374

      10 points yesterday

      Profile
      Rank: Genius

    Hall Of Fame