Give example for creating backup device and database backup using SQLDMO
Posted on 2001-07-17
I want to take the database backup using SQL-DMO.
I am using SQL-Server7.0 as a database. I am facing a problem while creating a backup device. So please give me example of creation of a new device and using same device give me the example of database backup.
Following is the code which i have wrriten
Private Sub cmdDevice_Click()
Dim oBackupDevice As New SQLDMO.BackupDevice
Dim oBackup As New SQLDMO.Backup
Dim oSQLServer As New SQLDMO.SQLServer
'Connect to the SQL-Server
oSQLServer.LoginTimeout = 0
oSQLServer.Connect "SERVER", "sa", ""
On Error GoTo ErrDeviceDoesNotExist
'Creation of new device
oBackupDevice.Name = "ISROBAK"
oBackupDevice.PhysicalLocation = "C:\ISROBAK.bak"
oBackupDevice.Type = SQLDMODevice_DiskDump
'Add device to the SQL-Server
'Take the backup
oBackup.Devices = oBackupDevice.Name
oBackup.BackupSetName = "ISRO Database backup "
oBackup.Files = oBackupDevice.PhysicalLocation
oBackup.Action = SQLDMOBackup_Database
oBackup.Database = "ISRO"
oBackup.MediaName = "ISROBAK.bak"
Above code is creating the device called "ISROBAK" but while taking the
backup (oBackup.SQLBackup oSQLServer) it is giving the following errors.
1. Cannot open basckup device 'C:\ISROBAK.BAK'. Device error or device off-line. See SQL Server error log for more details. Backup or restore operastion terminating abnormally
2. From the SQL Error log : 2001-07-18 09:01:25.48 kernel BackupDiskFile::CreateMedia: Backup device 'C:\ISROBAK.bak' failed to create. Operating system error = 32(The process cannot access the file because it is being used by another process.).