备份和还原SQL数据库
来源:互联网 发布:node vue webpack 编辑:程序博客网 时间:2024/04/30 11:20
'过程名称: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
'功能描述:备份数据库
'接收参数:需要备份的路径及文件名
'返回参数: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
- 备份和还原SQL数据库
- 备份和还原SQL数据库
- [转]备份和还原SQL数据库
- SQL语句备份和还原数据库
- SQL 语句备份和还原数据库
- sql语句数据库备份和还原
- SQL语句备份和还原数据库
- Sql Server 2008数据库备份和还原
- sql server数据库的备份和还原
- SQL Server2014数据库的备份和还原
- sql 数据库备份还原
- sql 备份还原数据库
- sql 备份还原数据库
- SQL数据库备份还原
- SQL备份和还原
- SQL备份和还原
- 备份和还原数据库
- 备份和还原数据库
- 著书立说
- 偷着减肥?
- 如何截取指定长度汉字而不会出现以"?>"结尾,超出部分以"..."代替
- 程序员,你离坐牢还有多远
- mysql Connection timed out
- 备份和还原SQL数据库
- Visual Studio .NET 已检测到指定的Web服务器运行的不是ASP.NET 1.1 版。您将无法运行ASP.NET Web应用程序或服务。 ---解决方法
- C 定时器
- 项目初期阶段
- 程序员,你离坐牢还有多远(转)
- 如何利用PHP上传文件
- SOAP协议浅析
- 如何提高你网站的访问量
- 修改MySQL的用户,密码