asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search










Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Moving a Database from SQL Server 7.0 to SQL Server 2000
By Dina Fleet Berry
Rating: 3.8 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction

    Moving or copying a SQL Server database from one machine to another requires a lot of preparation in order to ensure a smooth transfer. When moving from SQL Server 7.0 to SQL Server 2000, there are 4 choices in how to implement the transfer:

    1. Backup and Restore
    2. sp_detach and sp_attach
    3. Import and Export Data
    4. Upgrade the original server to 2000, then transfer the databases to the new server

    Each of these has its own issues you will need to review. This article assumes that the SQL Administrator is performing all tasks.

    The Master Database

    The first choice to determine is any of the data needed is in the Master database. Login information, Jobs, Alerts, Backups, and DTS packages are some of the items kept in the master database. If you know that each/all of your databases to move from SQL Server 7.0 to SQL Server 2000 needs information kept in the master database, you should upgrade the original server to 2000. After the upgrade is successful, move the databases from the original server to the new server. This is the easiest method if time and licensing are not considerations.

    If upgrading the original server is not a choice, the next best choice is to use the Import and Export Data method. This method is best done by someone that understands T-SQL and is comfortable adding, modifying, or deleting SQL commands.

    The Backup/Restore and Detach/Attach methods are poor choices if you need the master database, because both of these methods are best used for databases other than the master.

    Business Case

    I was asked to move a SQL Server 7.0 database to a newly installed SQL Server 2000 server. The database would be the only database on the new server and the old SQL Server Master database information would either not be necessary or setup by someone else. Because of the timing, the database would be moved but the original database on the original server would not be deleted from some time.

    Backup and Restore & Sp_detach and Sp_Attach

    These two methods work best if the destination server is configured exactly like the original server in terms of SQL configuration including location on the physical hard drive. These two methods can be the quickest transfer choice if the conditions are right because SQL Server does most of the work and asks very few questions. Since there is little to choose to configure, these two methods can be quick and easy to perform.

    Backup and Restore is completed from inside the SQL Enterprise manager. Sp_detach and sp_attach are completing using SQL Query Analyzer (or any tool that will execute SQL code).

    Import and Export Data

    Import and Export data makes a SQL DTS package of instructions for data to export. This becomes a SQL script. If you are a SQL programmer, instead of a SQL IT admin, you may find this method easiest. You can open the SQL script and alter it to add or change any code. Unless both servers are identical in configuration, you will probably have to edit the script in order for it to run without errors.

    MethodBest UsedUsed By
    Backup and RestoreData Database only - no master data neededIT admin
    sp_detach and sp_attachData Database only - no master data neededSQL Developer
    Import and Export DataMaster and Data databaseIT with T-SQL knowledge or SQL Developer
    Upgrade version, then transferMaster and Data databaseIT admin

    Requires more time and possibly additional license

    Business Case - Choosing Backup and Restore

    I choose backup to begin the process and T-SQL restore because I only needed the database (nothing from the Master) but the file path and database name were changing from the old server to the new server. The rest of this article focuses on this method of moving a database.

    Stop All Applications/Connections of Original Database

    Stopping the applications may involve stopping a web site, closing a port on a firewall, or some other action to make sure the connections between the calling applications and the database are closed.

    Backup of Original SQL Server 7.0 Database

    Make sure the original database is in read-only mode and allows only 1 user logged on at a time. This ensures that the database is not changing while the transfer is in progress. In my business case, I knew the original database would stay online but not be used. Read-only mode was a great way to ensure the applications using the database couldn't alter the old database after the transfer was completed.

    In the Enterprise Manager, select the database from the tree-view, right-click and choose Properties. On the Options tab, check Read-only and check Restrict Access for single user.

    The next step on the original server is to make a backup of the database. It's important to backup the entire database and overwrite existing media (ie, create a new file). If you have naming conventions for nightly backups, you may want to name the file differently so the file is not easily confused with nightly backups or backup to a different location.

    Make a note of the backup file name and location. You may need this in the next step.

    Changing File/Path Location During the Move

    If the old server file path and database name will be different from the new file path and database name, you will need to determine the exact old server data and log file names. This information is stored in the backup file you just made. In SQL Query Analyzer, execute:

        restore filelistonly from disk='filepath\filename.bak'

    example:

        restore filelistonly from disk='c:\sql\backup\mybackup.bak'

    SQL Query Analyzer will return a result set including the PhysicalName of the two files. Make note of these two names, such as 'test_data.mdf' and 'test_log.ldf'.

    Move the Backup File

    Move the backup file (*.bkf) to a location where the new server can find it, if necessary.

    Restore to New SQL Server 2000 Database

    In order to change the location of the database name and path, I used the T-SQL restore command in SQL Query Analyzer connected to the new Server:

        restore database DatabaseName
        from disk = 'c:\DatabaseName.bak'
        with move 'DatabaseNameData' to 'd:\DatabaseNameData.mdf',
        move 'DatabaseNameLog' to 'd:\DatabaseNameLog.ldf',
        replace

    This changed the location of the database from the old server's path on c:\ to the new server's path on d:\.

    The database is now restored on the new server. If you need to add anything to the master database on the new server, now is the time. This includes Logins, re-indexing, Jobs, Alerts, etc.

    Stop and Start SQL Server.

    Restart any Applications

    Any calling applications will need to change their connection information to point to the new server and new database. Since the old database on the old server is still in read-only, 1 person mode, it will be easy to tell when an application has not made the switch.

    Changes to Other Applications

    As an IT Administrator or Developer, you may find some of your other software tools may not work as expected. For example, Microsoft Access may not be able to connect to the new SQL Server by default. This is a compatibility issue and can be resolved by executing T-SQL on the new server:

        Exec sp_dbcmptlevel 'db',80

    Now Microsoft Access should be able to connect to the SQL Server 2000 without any problems.

    Summary

    Moving a database between two databases appears to be an easy task. The complexity of the database and the different versions of the software can make the job challenging. There are several methods to moving a database. Each should be evaluated for the specific move you have in mind.

    KnowledgeBase Articles

    There are several Microsoft Knowledgebase articles about moving or copying databases. There are kernels of information in all the articles. Here are some starter articles:

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    Proposion N2N
    Proposion N2N connects Microsoft .NET applications to Lotus Notes and Lotus Domino databases. This ADO.NET managed data provider allows you to perform blindingly fast queries and updates of Notes data from ASP.NET pages, .NET web services, Windows, or Mobile applications. An innovative SQL-like query language leverages the unique features of Notes and makes collaborative software accessible to relational database programmers.
    [Top]
    Other Articles
    Sep 15, 2005 - Building an Image Keyword System
    Unlike text-based file formats image files aren't made up of words, which makes searching for an image file by keyword difficult. Instead of being able to simply open the file to see what it contains, we're stuck looking at the text around it and other metadata to determine the image's meaning. In this article, Ziran Sun shows you how to build a simple database-based image keyword system that allows you to associate keywords with images and use these keywords to make finding images easier.
    [Read This Article]  [Top]
    Apr 7, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 2
    In the second part of of his article on using MySQL with ASP.NET, Ziran Sun covers how to add a new MySQL user to the database server, assign the user the appropriate permissions, connect to the database, and build a simple ASP.NET page to perform a query.
    [Read This Article]  [Top]
    Feb 10, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 1
    Back in the days of classic ASP, if you were building a database-driven web site, your choice was either to invest a lot of money to get a copy of Microsoft SQL Server (or some other enterprise-ready database) or invest a lot of time finding a way to deal with the performance and scalability limitations of Microsoft Access. Luckily these days there's another viable alternative: MySQL.
    [Read This Article]  [Top]
    Jan 6, 2005 - Debugging a SQL Stored Procedure from inside SQL Server 2000 Query Analyzer
    There are many times when using SQL Server 2000 Query Analyzer to debug SQL statements is a better choice than debugging in Visual Studio .NET. In this article, Dina Fleet Berry explains why and walks you through the debugging process step-by step.
    [Read This Article]  [Top]
    Nov 24, 2004 - Persisting .NET Objects to SQL Server Using SQLXML and Serialization
    As a follow up to his article on retrieving objects from SQL Server using SQLXML and serialization, Gianluca Nuzzo discusses saving objects back to SQL Server using a schema definition file and updategrams.
    [Read This Article]  [Top]
    Sep 14, 2004 - Transaction Processing in ADO.NET 2.0
    One area that stands out when comparing ADO.NET 1.x to ADO.NET 2.0 is transaction processing. Bill Ryan shows just how easy transaction processing has become with the TransactionScope object in ADO.NET 2.0.
    [Read This Article]  [Top]
    Sep 8, 2004 - Custom Object Data Binding with .NET
    Developers often use brute force coding to marshal data between the GUI and application objects. In this article, Luther Stanton explains how to use .NET's out-of-the box data-binding functionality to make this job much easier.
    [Read This Article]  [Top]
    Sep 2, 2004 - Queue MSMQ Messages from SQL Server
    Learn how to create a console application to queue a message in Microsoft Message Queuing (MSMQ) and then use an extended stored procedure to call the console application from a SQL Server trigger.
    [Read This Article]  [Top]
    Aug 30, 2004 - Tuning Up ADO.NET Connection Pooling in ASP.NET Applications
    Connection pooling increases the performance of Web applications by reusing active database connections instead of creating a new connection with every request. This article shows how to monitor the connection pool, diagnose a potential problem, and apply the appropriate fix.
    [Read This Article]  [Top]
    Jul 13, 2004 - Retrieving Objects from SQL Server Using SQLXML and Serialization
    This article will describe how to design a data access layer for a set of entities. You'll learn how to write an XSD schema and design two simple helper classes -- one for reading an XML stream from SQL Server using SQLXML and another for deserializing the XML stream.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers