Sql Server Express Backup using vb.net 2008

Greetings Folks !

I'm using VS.net, VB.net 2008....sql Server Express

I need to create a routine to backup a existing database using VB.net.

The database is called ..... MyStuff

any help would be appreciated
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Norman MainaCommented:
I think what you are looking for is SMO API, Backup/Restore classes.

Sample code in VB and C# :

Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common

'--Declare the backup object

Dim WithEvents oBackup As New Backup

'--Method to take backup

Private Sub BackupSqlDatabase()

Dim conn As New ServerConnection(serverName, userName, passWd) ' -- 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.Repl… "\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
.Initialize = True
.Checksum = True
.ContinueAfterError = True
.Incremental = False
.LogTruncation = BackupTruncateLogType.Truncate
.SqlBackup(oSQLServer) ' backup SQL database
End With

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.