Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi all
 
Below is my restore command
 
RESTORE DATABASE " & cmbdatabase.Text & " FROM disk='" & OpenFileDialog1.FileName & "'  WITH MOVE 'a' TO 'C:\Backup\a.mdf', Move 'a_log' TO 'C:\Backup\a.ldf',REPLACE"
 
Now as you can see i am moving the .mdf and .ldf file to a location.so for the first time it's fine to move but from the second time it will not allow me to do so.although it's not giving any error ,but it's not giving the desired output
 
Please tell me the solution for this..
 
Thank you
Posted 8-Apr-13 1:33am
Edited 10-Apr-13 2:05am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I think it has to do with the file names. If the files you want to replace has the same name with the ones you are using to replace them then it will prevent you from doing so.
 
From my own practice, when backing-up, I normally store the file names with dates and when restoring, I rename them to the file name that I used initially. This prevents names conflict and help to be exact with which files to restore (more like a restore point with dates).
  Permalink  
Comments
Snehasish Nandy at 12-Apr-13 2:49am
   
Ya can u give me some idea of the code...
tarhex at 12-Apr-13 8:04am
   
'backup database
 

Try
Dim backupdate, newname As String
 
'backup database
backupdate = DateString
newname = "C:\backup\dbase" & "" + backupdate + "" & ".mdf"
 

'check if a current day backup exist
If System.IO.File.Exists(newname) Then
 

'if yes, delete the former backup and backup the new one the new one
 
System.IO.File.Delete(newname)
System.IO.File.Copy(Application.StartupPath & "\db\dbase.mdf", newname)
 
Else
 
'backup database
System.IO.File.Copy(Application.StartupPath & "\db\dbase.mdf", newname)
 

End If
 
Dim mymsg As New myMsgbox
 
'show user where to click to upload logo
With mymsg
 
.txtError.Text = "Database Backup Successful!"
.ShowDialog()
 
End With
 

Catch ex As Exception
 
Dim mymsg As New myMsgbox
 
'show user where to click to upload logo
With mymsg
 
.txtError.Text = "Error Backing Up Database, try again later!"
.ShowDialog()
 
End With
 
End Try
tarhex at 12-Apr-13 8:12am
   
Try
'string to hold file name and stream
 
Dim fileStream As Stream
 
openDialogBox.InitialDirectory = "c:\backup\" 'initial directory
openDialogBox.Filter = "Software Database files (*.mdf)|*.mdf" 'file filters
openDialogBox.RestoreDirectory = True
 

 

' If user selects OK, store file name and stream.
If (openDialogBox.ShowDialog() = DialogResult.OK) Then
fileName = openDialogBox.FileName
fileStream = openDialogBox.OpenFile()
fileStream.Close()
 
System.IO.File.Delete(Application.StartupPath & "\db\dbase.mdf")
System.IO.File.Copy(fileName, Application.StartupPath & "\db\dbase.mdf")
 
Dim mymsg1 As New myMsgbox
 
'show user where to click to upload logo
With mymsg1
 
.txtError.Text = "Database Restored Successfully!"
.ShowDialog()
 
End With
 
End If
 
Catch ex As Exception
 

Dim mymsg1 As New myMsgbox
 

With mymsg1
 
.txtError.Text = "Error! Could Not Restore Database, try again!"
.ShowDialog()
 
End With
 

End Try
 
openDialogBox.Dispose()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 11 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100