Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jazzyb
Starting Member
20 Posts |
Posted - 2012-06-23 : 11:37:59
|
Hi,I am using the (SQL Express ) bellow given code to restore data from *.bak file (A backup file creater earlier by SQL backup). Some times this do not restore the data and gives error "Restore Failed". But when I change the system date to next day date then it restore data successfully.What is the reason of this problem & How to solve this issue. VB code used is as follow: Try Dim strFileName As String Dim rstDb As New Restore Dim srv As Server srv = New Server("(local)\SQLEXPRESS") Dim db As Database db = srv.Databases("mydatabase") strFileName = txtrestore.Text rstDb.Database = db.Name rstDb.Action = RestoreActionType.Database rstDb.Devices.Add(New Microsoft.SqlServer.Management.Smo.BackupDeviceItem(strFileName, DeviceType.File)) rstDb.UnloadTapeAfter = True rstDb.ReplaceDatabase = True rstDb.SqlRestore(srv) Catch ex As Exception MsgBox(ex.Message) End TryThanks |
|
prett
Posting Yak Master
212 Posts |
Posted - 2012-06-25 : 01:38:17
|
Dear jazzyb,Please mention full error message ("Restore Failed")... |
|
|
jazzyb
Starting Member
20 Posts |
Posted - 2012-06-28 : 07:41:38
|
Friends,Finally I have got the solution, I have executed the queries in the below given order : 1. User Master2. ALTER DATABASE mydatabasename SET OFFLINE WITH Rollback Immediate3. Restore command as in question post.4. ALTER DATABASE mydatabasename SET ONLINENow it is working well.Thanks |
|
|
granuharmot
Starting Member
31 Posts |
Posted - 2014-09-23 : 05:22:09
|
unspammed |
|
|
|
|
|