我正在使用以下函數來備份使用SMO的SQL Server數據庫..但備份失敗...我不知道,爲什麼它失敗...任何幫助表示讚賞。SMO數據庫備份
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
您是否收到錯誤消息? – JNK 2012-01-13 16:15:41
備份失敗..有點......我沒有管理工作室安裝在我的電腦......是否是備份失敗的原因? – 2012-01-13 16:17:52
你不需要將連接設置爲:'Dim conn As New ServerConnection(「MONO-PC \\ SQLEXPRESS」)'(兩個反斜槓)? – 2012-01-13 16:18:18