Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Create backup of Database of SQL server from Client and server

Create backup of Database of SQL server from Client and server

Scheduled Pinned Locked Moved Database
databasecsharpsql-serversysadminhelp
8 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sunil goyalG
    wrote on last edited by
    #1

    hi all, i want to create backup of my database (related to SQL server Express 2005) from .NET application. Application is install on SERVER and some Client computer(which is connected to SERVER). I want to create backup from SERVER and client. for backup purpose i use following statement Dim cmd As SqlCommand cmd = New SqlCommand("Backup Database abc to disk = @BackUpPath") cmd.CommandType = CommandType.Text Dim RootPath1 As String = DestinationPath 'Path for create Backup Dim shellCommand As String = RootPath1 & "abc.bak" cmd.Parameters.AddWithValue("@BackUpPath", shellCommand) ExecuteRestoreCommandQuery(cmd, "master") and this is the procedure ExecuteRestoreCommandQuery Private Sub ExecuteRestoreCommandQuery(ByVal comm As SqlCommand, ByVal DatabaseName As String) Dim con1 As SqlConnection = Nothing Try con1 = New SqlConnection("Data Source=" & PublicServerName & "\" & PublicInstanceName & ";Initial Catalog=" & DatabaseName & ";User ID=sa;Password=password") comm.Connection = con1 con1.Open() comm.ExecuteNonQuery() con1.Close() Catch ex As Exception msgbox(ex.Message.ToString) If con1.State = ConnectionState.Open Then con1.Close() End If End Try End Sub but when i run above code then it Gives error "Can not open backup device" path ... Operating System Error 5(Access is denied.). BACKUP DATABASE is terminating abnormally." so how can i create backup from application which is installed on SERVER and CLIENT.

    S 1 Reply Last reply
    0
    • S sunil goyalG

      hi all, i want to create backup of my database (related to SQL server Express 2005) from .NET application. Application is install on SERVER and some Client computer(which is connected to SERVER). I want to create backup from SERVER and client. for backup purpose i use following statement Dim cmd As SqlCommand cmd = New SqlCommand("Backup Database abc to disk = @BackUpPath") cmd.CommandType = CommandType.Text Dim RootPath1 As String = DestinationPath 'Path for create Backup Dim shellCommand As String = RootPath1 & "abc.bak" cmd.Parameters.AddWithValue("@BackUpPath", shellCommand) ExecuteRestoreCommandQuery(cmd, "master") and this is the procedure ExecuteRestoreCommandQuery Private Sub ExecuteRestoreCommandQuery(ByVal comm As SqlCommand, ByVal DatabaseName As String) Dim con1 As SqlConnection = Nothing Try con1 = New SqlConnection("Data Source=" & PublicServerName & "\" & PublicInstanceName & ";Initial Catalog=" & DatabaseName & ";User ID=sa;Password=password") comm.Connection = con1 con1.Open() comm.ExecuteNonQuery() con1.Close() Catch ex As Exception msgbox(ex.Message.ToString) If con1.State = ConnectionState.Open Then con1.Close() End If End Try End Sub but when i run above code then it Gives error "Can not open backup device" path ... Operating System Error 5(Access is denied.). BACKUP DATABASE is terminating abnormally." so how can i create backup from application which is installed on SERVER and CLIENT.

      S Offline
      S Offline
      scottgp
      wrote on last edited by
      #2

      Are you sure that the account that SQL Server is running under has write permissions to wherever you are trying to back up to? Scott

      S 1 Reply Last reply
      0
      • S scottgp

        Are you sure that the account that SQL Server is running under has write permissions to wherever you are trying to back up to? Scott

        S Offline
        S Offline
        sunil goyalG
        wrote on last edited by
        #3

        scottgp wrote:

        Are you sure that the account that SQL Server is running under has write permissions to wherever you are trying to back up to?

        no idea about this thing. How can i find that whether any account have write permission? BTW i use sa account for create backup

        S 1 Reply Last reply
        0
        • S sunil goyalG

          scottgp wrote:

          Are you sure that the account that SQL Server is running under has write permissions to wherever you are trying to back up to?

          no idea about this thing. How can i find that whether any account have write permission? BTW i use sa account for create backup

          S Offline
          S Offline
          scottgp
          wrote on last edited by
          #4

          You may be connecting as sa, but I believe the backup is actually executed by the account that the SQL Server service is executing under. What version of SQL Server are you using? If it's 2005, you can use the SQL Server Configuration Manager to view and change what account it's using, or you can use the Services tool under Administrative Tools. Scott

          S 1 Reply Last reply
          0
          • S scottgp

            You may be connecting as sa, but I believe the backup is actually executed by the account that the SQL Server service is executing under. What version of SQL Server are you using? If it's 2005, you can use the SQL Server Configuration Manager to view and change what account it's using, or you can use the Services tool under Administrative Tools. Scott

            S Offline
            S Offline
            sunil goyalG
            wrote on last edited by
            #5

            scottgp wrote:

            I believe the backup is actually executed by the account that the SQL Server service is executing under

            how can i get the information about the account?

            scottgp wrote:

            If it's 2005, you can use the SQL Server Configuration Manager to view and change what account it's using,

            yes it is, It is Built in Account under which network service is selected.but how it affect backup process?

            S 1 Reply Last reply
            0
            • S sunil goyalG

              scottgp wrote:

              I believe the backup is actually executed by the account that the SQL Server service is executing under

              how can i get the information about the account?

              scottgp wrote:

              If it's 2005, you can use the SQL Server Configuration Manager to view and change what account it's using,

              yes it is, It is Built in Account under which network service is selected.but how it affect backup process?

              S Offline
              S Offline
              scottgp
              wrote on last edited by
              #6

              I guess the question is - does the Network Service account have access to whatever RootPath1/DestinationPath is in your code? Is DestinationPath on a network somewhere? Scott

              S 1 Reply Last reply
              0
              • S scottgp

                I guess the question is - does the Network Service account have access to whatever RootPath1/DestinationPath is in your code? Is DestinationPath on a network somewhere? Scott

                S Offline
                S Offline
                sunil goyalG
                wrote on last edited by
                #7

                one more silly question

                scottgp wrote:

                does the Network Service account have access to whatever RootPath1/DestinationPath is in your code? Is DestinationPath on a network somewhere?

                how can i find whether it is have access to given path? however an Access denied message is appear when i select any path except Backup folder of SQL Server

                S 1 Reply Last reply
                0
                • S sunil goyalG

                  one more silly question

                  scottgp wrote:

                  does the Network Service account have access to whatever RootPath1/DestinationPath is in your code? Is DestinationPath on a network somewhere?

                  how can i find whether it is have access to given path? however an Access denied message is appear when i select any path except Backup folder of SQL Server

                  S Offline
                  S Offline
                  scottgp
                  wrote on last edited by
                  #8

                  The normal way that you check permissions in Windows. Right-click on the directory in Windows Explorer to bring up the context menu and select properties. Then select the security tab. You can then add the Network Service account and grant it write permissions. Alternatively, you could run SQL Server under another account - one that already has write permissions. Scott

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups