我使用以下功能使用SMO备份SQL Server数据库..但备份失败...我不知道,为什么它失败...任何帮助表示赞赏。
Private Sub BackupSqlDatabase()
Dim conn As New ServerConnection("MONO-PC\SQLEXPRESS") ' -- set SQL server connection given the server name, user name and password
Dim oSQLServer As New Server(conn) '--create the SMO server object using connection
Dim OrigBackupPath As String = oSQLServer.Information.MasterDBPath.Replace("\DATA", "C:\Backup\DB_BACKUP_NAME.BAK") ' -- set the path where backup file will be stored
Dim bkDevItem As New BackupDeviceItem(OrigBackupPath, DeviceType.File) ' -- create SMO.Backupdevice object
With oBackup ' Set the backup object property
.Action = BackupActionType.Database
.Database = "LIC.MDF"
.Devices.Add(bkDevItem)
.Initialize = True
.Checksum = True
.ContinueAfterError = True
.Incremental = False
.LogTruncation = BackupTruncateLogType.Truncate
.SqlBackup(oSQLServer) ' backup SQL database
End With
End Sub
答案 0 :(得分:0)
您使用的是哪个版本的sql server?我正在使用我相信10.5(sql server 2008 R2 Service Pack 1)并且不支持SMO对象。
我现在使用sql调用。
BACKUP DATABASE DBNAMEHERE TO DISK = 'destPath' WITH FORMAT