' 过程名称:BackUpDataBase ' 功能描述:备份数据库 ' 接收参数:需要备份的路径及文件名 ' 返回参数:Ture,False 是否成功 ' 创建人员及日期:zzz@2006-11-15 Public Function BackUpDataBase() Function BackUpDataBase(ByVal sDBName As String) As Boolean '生成备份SQL语句 Dim backupSql As String, sComputerPath As String sComputerPath = SystemInformation.ComputerName 'sDBName = sDBName.Replace(":", "$") backupSql = "USE MASTER;" 'backupSql += "Backup DATABASE " & gDBName & " TO DISK='/" & sComputerPath & "" & sDBName & "';" backupSql += "Backup DATABASE " & gDBName & " TO DISK='" & sDBName & "';" '定义SqlCommand对象并执行 Dim myCommand As New SqlClient.SqlCommand Dim sqlCon As New SqlClient.SqlConnection sqlCon.ConnectionString = SqlConnectString myCommand.CommandText = backupSql myCommand.Connection = sqlCon Dim frmNewWait As New frmWaiting frmNewWait.Show() System.Windows.Forms.Application.DoEvents() Try sqlCon.Open() myCommand.ExecuteNonQuery() BackUpDataBase = True Catch ex As Exception Throw New Exception("Error In ExecuteTransaction!!!(DataBaseClose)" & vbCrLf & _ "Source:" & ex.Source.ToString() + " Message:" + ex.Message.ToString()) BackUpDataBase = False Finally frmNewWait.Close() If Not frmNewWait Is Nothing Then frmNewWait.Dispose() End If sqlCon.Close() sqlCon.Dispose() myCommand.Dispose() End Try End Function ' 过程名称:RestoreDataBase ' 功能描述:还原数据库 ' 接收参数:需要还原的路径及文件名 ' 返回参数:Ture,False 是否成功 ' 创建人员及日期:zzz@2006-11-15 Public Function RestoreDataBase() Function RestoreDataBase(ByVal sDBName As String) As Boolean '生成SQL语句 Dim RestoreSql As String RestoreSql = "USE MASTER;" '定义SqlCommand对象并执行 Dim myCommand As New SqlClient.SqlCommand Dim sqlCon As New SqlClient.SqlConnection sqlCon.ConnectionString = SqlConnectString myCommand.Connection = sqlCon Try sqlCon.Open() myCommand.CommandText = RestoreSql myCommand.ExecuteNonQuery() RestoreSql = "restore DATABASE " & gDBName & " FROM DISK='" & sDBName & "';" myCommand.CommandText = RestoreSql myCommand.ExecuteNonQuery() RestoreDataBase = True Catch ex As Exception Throw New Exception("Error In ExecuteTransaction!!!(DataBaseClose)" & vbCrLf & _ "Source:" & ex.Source.ToString() + " Message:" + ex.Message.ToString()) RestoreDataBase = False Finally sqlCon.Close() sqlCon.Dispose() myCommand.Dispose() End Try End Function