Tuesday, March 2, 2010

How to Copy or Move MS SQL Database

I was struggling and wasted couple of hours trying to move a MS SQL database to a new server. Reason was that I kept on getting some error messages that I really did not understand properly. Let us see how to copy a MS SQL database in couple of simple steps.

You can use Database Back Up and Restore function for this task without any problem. However, there are couple of error messages that you have to aware.

1. Back your database from the Original location (Server A)
2. Copy it to the new location (Server B)
3. Create a instant of a database in Server B and restore the backup copy that you took from server A

Yes, it is a quite simple process. Lets handle couple of error messages you might have to face while you trying to copy the database to new location.


Error Message: The backup set holds a backup of a database other than the existing database. (Microsoft.SqlServer.Express.SMo)


Solution: Go to Options page (Restore Database) and check the Overwrite the existing database option.

Error Message 02: System.Data.SqlClient.SqlError: Directory lookup for the file failed with the operating system error 3(The System cannot find the path specified.) (Microsoft.SqlServer.Express.Smo)


Solution: In the options Page (Restore Database) check the Restore the database files as: pane. If your new server is 64 bit it might still looking the files in Program Files folder but actually SQL is installed in Program File (x86). Select the correct path.

Error Message 03: System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.Express.Smo)
Solution: Open the SQL Server Configuration Manager and restart the SQL Server.
Blog Widget by LinkWithin