Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

SMO.Restore Database name change

 
   Database Help (Home) -> Programming RSS
Next:  sql query organizer recommendation  
Author Message
Landry, Eric

External


Since: May 14, 2008
Posts: 3



(Msg. 1) Posted: Wed May 14, 2008 12:22 pm
Post subject: SMO.Restore Database name change
Archived from groups: microsoft>public>sqlserver>programming (more info?)

I am restoring a database with SQL-SMO. Is there a way to restore to a
database with a differant name. For example, I have a backup of a database
called "DB1". I want to restore that database as "DB2". Bellow is the code
that I am using now.


Dim svr As Server = New Server("SERVER1")
Dim res As Restore = New Restore()

res.Devices.AddDevice("C:\Development\Projects\SQLAutoRestore\BackupFiles\db01.bak",
DeviceType.File)
res.Database = "DB2"
res.NoRecovery = False
res.ReplaceDatabase = True
res.SqlRestore(svr)

 >> Stay informed about: SMO.Restore Database name change 
Back to top
Login to vote
Tom Moreau

External


Since: Apr 21, 2004
Posts: 502



(Msg. 2) Posted: Wed May 14, 2008 1:46 pm
Post subject: Re: SMO.Restore Database name change [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

What error message are you getting?

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


"Landry, Eric" wrote in message

I am restoring a database with SQL-SMO. Is there a way to restore to a
database with a differant name. For example, I have a backup of a database
called "DB1". I want to restore that database as "DB2". Bellow is the code
that I am using now.


Dim svr As Server = New Server("SERVER1")
Dim res As Restore = New Restore()


res.Devices.AddDevice("C:\Development\Projects\SQLAutoRestore\BackupFiles\db
01.bak",
DeviceType.File)
res.Database = "DB2"
res.NoRecovery = False
res.ReplaceDatabase = True
res.SqlRestore(svr)

 >> Stay informed about: SMO.Restore Database name change 
Back to top
Login to vote
Landry, Eric

External


Since: May 14, 2008
Posts: 3



(Msg. 3) Posted: Wed May 14, 2008 1:46 pm
Post subject: Re: SMO.Restore Database name change [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Restore failed for Server 'SERVER1'.

"Tom Moreau" wrote in message

> What error message are you getting?
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
> SQL Server MVP
> Toronto, ON Canada
> https://mvp.support.microsoft.com/profile/Tom.Moreau
>
>
> "Landry, Eric" wrote in message
>
> I am restoring a database with SQL-SMO. Is there a way to restore to a
> database with a differant name. For example, I have a backup of a
> database
> called "DB1". I want to restore that database as "DB2". Bellow is the
> code
> that I am using now.
>
>
> Dim svr As Server = New Server("SERVER1")
> Dim res As Restore = New Restore()
>
>
> res.Devices.AddDevice("C:\Development\Projects\SQLAutoRestore\BackupFiles\db
> 01.bak",
> DeviceType.File)
> res.Database = "DB2"
> res.NoRecovery = False
> res.ReplaceDatabase = True
> res.SqlRestore(svr)
>
>
>
 >> Stay informed about: SMO.Restore Database name change 
Back to top
Login to vote
Tibor Karaszi

External


Since: Jan 29, 2004
Posts: 1559



(Msg. 4) Posted: Wed May 14, 2008 7:30 pm
Post subject: Re: SMO.Restore Database name change [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Perhaps if you use Profiler to catch the RESTORE command submitted by SMO, and we can work our
backwards by seeing that command?

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi


"Landry, Eric" wrote in message

> Restore failed for Server 'SERVER1'.
>
> "Tom Moreau" wrote in message
>
>> What error message are you getting?
>>
>> --
>> Tom
>>
>> ----------------------------------------------------
>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
>> SQL Server MVP
>> Toronto, ON Canada
>> https://mvp.support.microsoft.com/profile/Tom.Moreau
>>
>>
>> "Landry, Eric" wrote in message
>>
>> I am restoring a database with SQL-SMO. Is there a way to restore to a
>> database with a differant name. For example, I have a backup of a database
>> called "DB1". I want to restore that database as "DB2". Bellow is the code
>> that I am using now.
>>
>>
>> Dim svr As Server = New Server("SERVER1")
>> Dim res As Restore = New Restore()
>>
>>
>> res.Devices.AddDevice("C:\Development\Projects\SQLAutoRestore\BackupFiles\db
>> 01.bak",
>> DeviceType.File)
>> res.Database = "DB2"
>> res.NoRecovery = False
>> res.ReplaceDatabase = True
>> res.SqlRestore(svr)
>>
>>
>>
>
 >> Stay informed about: SMO.Restore Database name change 
Back to top
Login to vote
Landry, Eric

External


Since: May 14, 2008
Posts: 3



(Msg. 5) Posted: Wed May 14, 2008 7:30 pm
Post subject: Re: SMO.Restore Database name change [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks for the profiler idea. My backup was trying to overwrite the
original database files. I needed use a with move statement.


res.Devices.AddDevice(DevicePath, DeviceType.File)

Dim DataFile As New RelocateFile
Dim MDF As String = res.ReadFileList(svr).Rows(0)(1)
DataFile.LogicalFileName = res.ReadFileList(svr).Rows(0)(0)
DataFile.PhysicalFileName = Path.Combine(Path.GetDirectoryName(MDF),
DatabaseName & Path.GetExtension(MDF))

Dim LogFile As New RelocateFile
Dim LDF As String = res.ReadFileList(svr).Rows(1)(1)
LogFile.LogicalFileName = res.ReadFileList(svr).Rows(1)(0)
LogFile.PhysicalFileName = Path.Combine(Path.GetDirectoryName(LDF),
DatabaseName & Path.GetExtension(LDF))

res.RelocateFiles.Add(DataFile)
res.RelocateFiles.Add(LogFile)

res.Database = DatabaseName
res.NoRecovery = NoRecovery
res.ReplaceDatabase = True
res.SqlRestore(Server)


Thanks again.


"Tibor Karaszi" wrote in
message
> Perhaps if you use Profiler to catch the RESTORE command submitted by SMO,
> and we can work our backwards by seeing that command?
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
>
> "Landry, Eric" wrote in message
>
>> Restore failed for Server 'SERVER1'.
>>
>> "Tom Moreau" wrote in message
>>
>>> What error message are you getting?
>>>
>>> --
>>> Tom
>>>
>>> ----------------------------------------------------
>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
>>> SQL Server MVP
>>> Toronto, ON Canada
>>> https://mvp.support.microsoft.com/profile/Tom.Moreau
>>>
>>>
>>> "Landry, Eric" wrote in message
>>>
>>> I am restoring a database with SQL-SMO. Is there a way to restore to a
>>> database with a differant name. For example, I have a backup of a
>>> database
>>> called "DB1". I want to restore that database as "DB2". Bellow is the
>>> code
>>> that I am using now.
>>>
>>>
>>> Dim svr As Server = New Server("SERVER1")
>>> Dim res As Restore = New Restore()
>>>
>>>
>>> res.Devices.AddDevice("C:\Development\Projects\SQLAutoRestore\BackupFiles\db
>>> 01.bak",
>>> DeviceType.File)
>>> res.Database = "DB2"
>>> res.NoRecovery = False
>>> res.ReplaceDatabase = True
>>> res.SqlRestore(svr)
>>>
>>>
>>>
>>
>
 >> Stay informed about: SMO.Restore Database name change 
Back to top
Login to vote
Tibor Karaszi

External


Since: Jan 29, 2004
Posts: 1559



(Msg. 6) Posted: Thu May 15, 2008 9:28 am
Post subject: Re: SMO.Restore Database name change [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Glad you found a solution. I frequently use Profiler whenever I use some API that "does something
strange".

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi


"Landry, Eric" wrote in message

> Thanks for the profiler idea. My backup was trying to overwrite the original database files. I
> needed use a with move statement.
>
>
> res.Devices.AddDevice(DevicePath, DeviceType.File)
>
> Dim DataFile As New RelocateFile
> Dim MDF As String = res.ReadFileList(svr).Rows(0)(1)
> DataFile.LogicalFileName = res.ReadFileList(svr).Rows(0)(0)
> DataFile.PhysicalFileName = Path.Combine(Path.GetDirectoryName(MDF), DatabaseName &
> Path.GetExtension(MDF))
>
> Dim LogFile As New RelocateFile
> Dim LDF As String = res.ReadFileList(svr).Rows(1)(1)
> LogFile.LogicalFileName = res.ReadFileList(svr).Rows(1)(0)
> LogFile.PhysicalFileName = Path.Combine(Path.GetDirectoryName(LDF), DatabaseName &
> Path.GetExtension(LDF))
>
> res.RelocateFiles.Add(DataFile)
> res.RelocateFiles.Add(LogFile)
>
> res.Database = DatabaseName
> res.NoRecovery = NoRecovery
> res.ReplaceDatabase = True
> res.SqlRestore(Server)
>
>
> Thanks again.
>
>
> "Tibor Karaszi" wrote in message
>
>> Perhaps if you use Profiler to catch the RESTORE command submitted by SMO, and we can work our
>> backwards by seeing that command?
>>
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>>
>> "Landry, Eric" wrote in message
>>
>>> Restore failed for Server 'SERVER1'.
>>>
>>> "Tom Moreau" wrote in message
>>>
>>>> What error message are you getting?
>>>>
>>>> --
>>>> Tom
>>>>
>>>> ----------------------------------------------------
>>>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
>>>> SQL Server MVP
>>>> Toronto, ON Canada
>>>> https://mvp.support.microsoft.com/profile/Tom.Moreau
>>>>
>>>>
>>>> "Landry, Eric" wrote in message
>>>>
>>>> I am restoring a database with SQL-SMO. Is there a way to restore to a
>>>> database with a differant name. For example, I have a backup of a database
>>>> called "DB1". I want to restore that database as "DB2". Bellow is the code
>>>> that I am using now.
>>>>
>>>>
>>>> Dim svr As Server = New Server("SERVER1")
>>>> Dim res As Restore = New Restore()
>>>>
>>>>
>>>> res.Devices.AddDevice("C:\Development\Projects\SQLAutoRestore\BackupFiles\db
>>>> 01.bak",
>>>> DeviceType.File)
>>>> res.Database = "DB2"
>>>> res.NoRecovery = False
>>>> res.ReplaceDatabase = True
>>>> res.SqlRestore(svr)
>>>>
>>>>
>>>>
>>>
>>
>
 >> Stay informed about: SMO.Restore Database name change 
Back to top
Login to vote
Rashmi S

External


Since: Sep 13, 2010
Posts: 1



(Msg. 7) Posted: Mon Sep 13, 2010 1:25 am
Post subject: Restoring backup created on one server onto another server SMO in [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hello,

I have created backup of the database programatically. The Database is DB1 and it is on server SER1.
The backup file is sitting on C:\.... on SER1.
Now I want to restore this backup file on another server SER2 with same name or different name.
Any ideas about this?
I do not have any common fileshare location where I can move .bak file from SER1 at present.
Thank you very much !

-Rashmi

> On Wednesday, May 14, 2008 1:22 PM Landry, Eric wrote:

> I am restoring a database with SQL-SMO. Is there a way to restore to a
> database with a differant name. For example, I have a backup of a database
> called "DB1". I want to restore that database as "DB2". Bellow is the code
> that I am using now.
>
>
> Dim svr As Server = New Server("SERVER1")
> Dim res As Restore = New Restore()
>
> res.Devices.AddDevice("C:\Development\Projects\SQLAutoRestore\BackupFiles\db01.bak",
> DeviceType.File)
> res.Database = "DB2"
> res.NoRecovery = False
> res.ReplaceDatabase = True
> res.SqlRestore(svr)


>> On Wednesday, May 14, 2008 1:46 PM Tom Moreau wrote:

>> What error message are you getting?
>>
>> --
>> Tom
>>
>> ----------------------------------------------------
>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
>> SQL Server MVP
>> Toronto, ON Canada
>> https://mvp.support.microsoft.com/profile/Tom.Moreau
>>
>>
>> "Landry, Eric" wrote in message
>>
>> I am restoring a database with SQL-SMO. Is there a way to restore to a
>> database with a differant name. For example, I have a backup of a database
>> called "DB1". I want to restore that database as "DB2". Bellow is the code
>> that I am using now.
>>
>>
>> Dim svr As Server = New Server("SERVER1")
>> Dim res As Restore = New Restore()
>>
>>
>> res.Devices.AddDevice("C:\Development\Projects\SQLAutoRestore\BackupFiles\db
>> 01.bak",
>> DeviceType.File)
>> res.Database = "DB2"
>> res.NoRecovery = False
>> res.ReplaceDatabase = True
>> res.SqlRestore(svr)


>>> On Wednesday, May 14, 2008 2:46 PM Landry, Eric wrote:

>>> Restore failed for Server 'SERVER1'.


>>>> On Wednesday, May 14, 2008 2:59 PM Tibor Karaszi wrote:

>>>> Perhaps if you use Profiler to catch the RESTORE command submitted by SMO, and we can work our
>>>> backwards by seeing that command?
>>>>
>>>> --
>>>> Tibor Karaszi, SQL Server MVP
>>>> http://www.karaszi.com/sqlserver/default.asp
>>>> http://sqlblog.com/blogs/tibor_karaszi
>>>>
>>>>
>>>> "Landry, Eric" wrote in message
>>>>


>>>>> On Wednesday, May 14, 2008 5:50 PM Landry, Eric wrote:

>>>>> Thanks for the profiler idea. My backup was trying to overwrite the
>>>>> original database files. I needed use a with move statement.
>>>>>
>>>>>
>>>>> res.Devices.AddDevice(DevicePath, DeviceType.File)
>>>>>
>>>>> Dim DataFile As New RelocateFile
>>>>> Dim MDF As String = res.ReadFileList(svr).Rows(0)(1)
>>>>> DataFile.LogicalFileName = res.ReadFileList(svr).Rows(0)(0)
>>>>> DataFile.PhysicalFileName = Path.Combine(Path.GetDirectoryName(MDF),
>>>>> DatabaseName & Path.GetExtension(MDF))
>>>>>
>>>>> Dim LogFile As New RelocateFile
>>>>> Dim LDF As String = res.ReadFileList(svr).Rows(1)(1)
>>>>> LogFile.LogicalFileName = res.ReadFileList(svr).Rows(1)(0)
>>>>> LogFile.PhysicalFileName = Path.Combine(Path.GetDirectoryName(LDF),
>>>>> DatabaseName & Path.GetExtension(LDF))
>>>>>
>>>>> res.RelocateFiles.Add(DataFile)
>>>>> res.RelocateFiles.Add(LogFile)
>>>>>
>>>>> res.Database = DatabaseName
>>>>> res.NoRecovery = NoRecovery
>>>>> res.ReplaceDatabase = True
>>>>> res.SqlRestore(Server)
>>>>>
>>>>>
>>>>> Thanks again.
>>>>>
>>>>>
>>>>> "Tibor Karaszi" wrote in
>>>>> message


>>>>>> On Thursday, May 15, 2008 3:28 AM Tibor Karaszi wrote:

>>>>>> Glad you found a solution. I frequently use Profiler whenever I use some API that "does something
>>>>>> strange".
>>>>>>
>>>>>> --
>>>>>> Tibor Karaszi, SQL Server MVP
>>>>>> http://www.karaszi.com/sqlserver/default.asp
>>>>>> http://sqlblog.com/blogs/tibor_karaszi
>>>>>>
>>>>>>
>>>>>> "Landry, Eric" wrote in message
>>>>>>


>>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>>> Lucene.Net Indexing Searching Entry Level Tutorial
>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/c69ef65f-e3c6-409e-ab97-16...7c74f83
 >> Stay informed about: SMO.Restore Database name change 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Restore a copy of a database with different name - Hi, Simple question: I would like to retore a backup database as a copy with a different name. So now I would have 2 identical databases but, with different names. When I run this I get errors complaining about overriding mdf files and ldf files. Wel...

Restore Database and Transaction logs - Hi all, using SQL 2000 sp4 I have a production database that is set at full mode. I do backups nightly on the database and backup transactions every 2 hours. I would like to test run a restore into a new database name and only upto a certain..

Restore a database from 2 .gz files - Hi, Can someone please help me with the syntax to restore a database from 2 ..gz files. This is the syntax I have so far but I don't know what I need to modify to correct my syntax errors: RESTORE DATABASE p_dbcon001 FROM DISK =..

Backup and Restore database using T-SQL - Hello, Is it possible to backup and restore a database using T-SQL? I need to backup the database, log and filegroup to a specific folder and verify that everything is ok. And later I would like to restore it. I suppose I can't backup and restore the...

Database Restore Problem SQL Server 2005 - Hi OS Windows server 2003 SP1 SQL Server 2005 Slandered Edition We try to restore the backup from the bak file and it is giving the following message System.Data.SqlClient.SqlError : Restore Detected an error on page (0:0) in database "Database...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]