如何进行数据库备份

问题描述:

亲爱的所有



如何在sql server 2008中进行数据库备份



我的数据库位置: C:\Program Files \ Microsoft SQL Server \ MSSQL10.SQLEXPRESS \ MSSQL \DATA\Test.mdf



i am using using Button。当我点击命令按钮,那时我想在D:\ BackupFount数据库中保存数据库。\\ test.mdf



请告诉我..我是怎么做的

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

'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