Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thanks in advance,

Front end : Visual Studio 2010.
Back end : SQL Server 2005/2008 and SQL 2012 express.

I have created a small application which takes SQL Server database backup on desired location it works fine with SQL Server 2005/2008 but in case of SQL Express 2012
it gives error backup Failed for the Server.

Question:
1). Can i take backup Using my application as Front end and SQL Server 2012
or any Express SQL version as back end.
2). Is it because of SQL Express
3). My smo dll reference is of SQL 2005 that's why it's not taking backup ,
because the Express version is 2012

Any Solution/Idea/Links will be highly appreciated.




Here is the code
Public Function BackUP() As Boolean
        Try

            Application.DoEvents()
            Dim conn As New ServerConnection(gSrv, gDbUsrID, gDbUsrPass)
            Application.DoEvents()
            Dim oSQLServer As New Server(conn)
            Application.DoEvents()

            If My.Computer.FileSystem.DirectoryExists(txtPath.Text) = False Then
                My.Computer.FileSystem.CreateDirectory(txtPath.Text)
            End If

            Dim OrigBackupPath As String = txtPath.Text  
            Application.DoEvents()
            Dim bkDevItem As New BackupDeviceItem(txtPath.Text & "\DB_BACKUP.BAK", DeviceType.File)
            Application.DoEvents()
            With oBackup
                .Action = BackupActionType.Database
                .Database = "DbName"
                .Devices.Add(bkDevItem)
                .Initialize = True
                .Checksum = True
                .ContinueAfterError = True
                .Incremental = False
                .LogTruncation = BackupTruncateLogType.Truncate
                Application.DoEvents()
                .SqlBackup(oSQLServer)
                Application.DoEvents()
                Process.Start("explorer.exe", OrigBackupPath)
                BackUP = True
            End With
            Return BackUP
        Catch ex As Exception
            MessageBox.Show(ex.Message, "*", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function
Posted
Updated 9-Dec-12 23:41pm
v3
Comments
ssd_coolguy 27-Dec-12 6:52am    
why don't you use single command to take backup of sql server..
backup database dbname to disk= 'F:\dbname.bak'
εїзεїзεїз 27-Dec-12 7:47am    
Thanks for the comment , Yes Finally , i did that but the above code still did not work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900