不一定要指定:DMOBackup.Devices = "ac"
Examples
A. Performing a Complete Database Backup
This example illustrates using SQL-DMO to perform a complete database backup.' Create a Backup object and set action and source database properties.
Dim oBackup As New SQLDMO.Backup
oBackup.Action = SQLDMOBackup_Database
oBackup.Database = "Northwind"' Example illustrates a striped backup using two target devices. Note:
' Device creation is not illustrated in this example.
oBackup.Devices = "[NorthDev1],[NorthDev2]"' Optional. Backup set name and description properties provide
' descriptive text when backup header is displayed for the device(s).
oBackup.BackupSetName = "Northwind_Full"
oBackup.BackupSetDescription = "Full backup of Northwind sample."' Call SQLBackup method to perform the backup. In a production
' environment, consider wrapping the method call with a wait pointer
' or use Backup object events to provide feedback to the user.
'
' Note: Create and connect of SQLServer object used is not
' illustrated in this example.
oBackup.SQLBackup oSQLServer

解决方案 »

  1.   

    用SQL Server的SQLDMO编程’服务器
    Dim gSQLServer As SQLDMO.SQLServer
    '备分
    Dim WithEvents oBackupEvent  As SQLDMO.Backup
    ’还原
    Dim WithEvents oRestoreEvent As SQLDMO.RestoreVB示例如下:
    ’COMMAND CLICK 事件Private Sub cmdBack_Click()
        On Error GoTo ErrHandler:
        
        Dim oBackup As SQLDMO.Backup
        
        gDatabaseName = "Business"   ‘数据库名字
        Set oBackup = New SQLDMO.Backup
        Set oBackupEvent = oBackup ' enable events
        
        oBackup.Database = gDatabaseName
        gBkupRstrFileName = txtDataFileName.Text   ‘要备份的文件名
        oBackup.Files = gBkupRstrFileName
        
        If Len(Dir(gBkupRstrFileName)) > 0 Then
            Kill (gBkupRstrFileName)
        End If
        
        Screen.MousePointer = vbHourglass
        ‘备份
        oBackup.SQLBackup gSQLServer
        
        Screen.MousePointer = vbDefault
       
        Set oBackupEvent = Nothing ' disable events
        Set oBackup = Nothing
        
        Exit SubErrHandler:
        MsgBox "Error " & Err.Description
        Resume Next
    End Sub