Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All

How to Make Database Backup in sql server 2008

my database location : C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Test.mdf

i am using command Button. When i click Command Button that time i want to store database in D:\Backup Database\Test.mdf

Please tell me.. how i do for this
Posted
Comments
ZurdoDev 18-Apr-13 11:20am    
That isn't exactly a backup, but a copy. You could just use File.Copy
http://msdn.microsoft.com/en-us/library/system.io.file.aspx Otherwise, issue a SQL command to do an actual backup.

1 solution

VB
'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 that backup is successful
            With mymsg

                .txtError.Text = "Database Backup Successful!"
                .ShowDialog()

            End With


        Catch ex As Exception

            Dim mymsg As New myMsgbox

            'show an error when backup is not successful
            With mymsg

                .txtError.Text = "Error Backing Up Database, try again later!"
                .ShowDialog()

            End With

        End Try
 
Share this answer
 
v2
Comments
Navas Khanj 19-Apr-13 10:43am    
Thanks

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900