CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Sep 2021
    Posts
    2

    SQL Server database backup problem

    I am using SQL Server 2014 Express with Visual Basic 2013 (Professional edition)

    I can backup a database but have a problem that I cannot solve. If I keep clicking on the button to save the database, it does not add a new file based on the time of saving nor does it overwrite to old file. It keeps appending data to the existing file. The file size just gets bigger and bigger.

    Here is my save code:

    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Try
                Dim connection As String = ("Data Source=Apollo\sqlexpress;Initial Catalog=Calendar;Integrated Security=True")
    
                Dim conn As New SqlConnection(connection)
                conn.Open()
    
                Dim cmd As New SqlCommand
                cmd.CommandType = CommandType.Text
                cmd.CommandText = "BACKUP DATABASE Calendar TO DISK='D:\Temp\Calendar.BAK  '"
                cmd.Connection = conn
                cmd.ExecuteNonQuery()
    
                conn.Close()
    
                MsgBox("Data saved")
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    I hope that I have inserted the code correctly. I have not used this site for many years and then under another user name and email address

    Can someone help please?
    Last edited by VictorN; September 13th, 2021 at 07:05 AM. Reason: replace the QUOTE tags with the CODE ones

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured