Hi,

Need help in creating backup/restore on database using SQL Server 2005 with VB6.0 code when the database is on the network.

Please Help.

frexyang

Thank you for opening your own thread.:)

The attached file will help you in getting the backup sorted. You will however need to play with the code to suit your needs, getting the connection on the network, sorting sql user privileges etc.

The code is not by me, all credit to the developer.

Thank you for replying. I will try it right now.

Please help if you have a sample code using SQLDMO w/c creates *.bak file for data sql server 2005 database backup.

my code so far:

Public Function BackUpDatabase() As Boolean
Dim objBackup As New SQLDMO.Backup
Dim objServer As New SQLDMO.SQLServer
Dim objDevice As New SQLDMO.BackupDevice

objDevice.Type = SQLDMODevice_DiskDump
objDevice.Name = "SamplesDeviceBackup"
objDevice.PhysicalLocation = "C:\SAMPLEBACKUP.BAK"

objServer.Connect "[networkservername]", "[username]", "[password]"
objServer.BackupDevices.Add objDevice

objBackup.Action = SQLDMOBackup_Database
objBackup.Database = "SAMPLEDATABASE"
objBackup.Devices = "SamplesDeviceBackup"
objBackup.BackupSetDescription = "Sample Database Backup"
objBackup.BackupSetName = "Rex"

If Err.Number >= 0 Then
BackUpDatabase = True
Else
objBackup.Abort
BackUpDatabase = False
MsgBox "Error Occured : " & Err.Description & " " & Err.Number
Exit Function
End If

'objServer.KillProcess 1
End Function

: the problem is I cant find the .bak file on the drive specified. the backup is successfull as per message and the process took around 1-2 min after it gives out the message.
: the server is on the network. SQL Server 2005 and it is installed on Microsoft Windows Server 2003.

Please help your help on this...

Thank you in advance.

Do you have hidden files made visible? a .bak file is normally saved as a hidden file, hence you can't find it.

Otherwise, try and use some different code for the path to save to.:)

i've already tried to set the hidden files being shown already. But I will try to check the server if the its save in it.

Thank you again for replying.

No problem. Let me know how it went.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.