Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Backup/Restore database using SQL-DMO

Posted on 2002-03-27
3
Medium Priority
?
719 Views
Last Modified: 2007-12-19
Hi, all,

I am using SQL-Server 2000, VC++6.0, SQL-DMO and I am trying to backup/restore a database. Here is what I need:

1. Backup a database, saying A. Then then I got a file say FileA.

2. Create a database B.

3. "Restore" database B based on FileA on the SAME SQLServer. Basically, I want everything in database B is exactly the same as database B.

The problem I got is SQL-DMO complains that the Data file of A (..\Microsoft SQLServer\MSSQL\DATA\A_Data.MDF) is being used.

The key point here:

1. In the backup file. I assume it keeps the data file name A_Data.MDF, A_Log.Ldf, ...
2. Since I need to "restore"(or I should say create) the database B from backup file A in the same SQL server, but File A is still being used, that causes problem.
3. If there is a way somehow rename A_Data.MDF, A_Log.Ldf in the backup file, then I guess the problem can be solved.

Any hints ? Please help.

Thanks.




0
Comment
Question by:mikechen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Expert Comment

by:Cool2k
ID: 6901417
Setting the property DatabaseFiles of Restore/backup object may help you. I never tried.

I am also interested in knowing the answer.

Magesh
0
 
LVL 32

Accepted Solution

by:
Brendt Hess earned 800 total points
ID: 6903353
You need to look at the RelocateFiles property.  This tells DMO where, and with what name, the files are to be restored.

Here's a VB example:

Option Explicit
Dim oSQLDMOSQLServer
Dim oSQLDMORestore

Set oSQLDMOSQLServer = CreateObject("SQLDMO.SQLServer")
oSQLDMOSQLServer.LoginSecure = True
oSQLDMOSQLServer.Connect "MyServer"

Set oSQLDMORestore = CreateObject("SQLDMO.Restore")
oSQLDMORestore.Database = "Northwind2"
oSQLDMORestore.Files = "C:\Backups\NorthwindBackup.bak"
oSQLDMORestore.RelocateFiles = _
    "[Northwind]" & "," & "[c:\temp\Northwind2.mdf]" & "," & _
    "[Northwind_log]" & "," & "[c:\temp\Northwind2.ldf]"

oSQLDMORestore.SQLRestore(oSQLDMOSQLServer)
0
 

Author Comment

by:mikechen
ID: 6907750
Thank you for your information.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question