I have completed my project with front-end as vb.net 2008 and back-end as SQL server 2005. I have to backup and restore my project in the following extensions:
1. .bak
2. .xls
3. .mdb
Please tell me how can i store the backup project in my own path.

To take back up in .bak extension file
1. Right click on ur database name
2. Tasks -> back up -> Set the backup location and then click on OK.

To restore the .bak extension file
1. Right click on ur database name
2. Tasks ->Restore -> Database
3. Set the database name if the textbox is empty
4. Source for restore -> From database / from device
5. if from device...select the radio button and then click on browse
6. Click on Add -> then select the .bak file from ur correct path
7. Clck OK
8. Select the check box of the appropriate database from the list and click OK.

if u want to add the same in code...then do the following

Try
   If Not Directory.Exists("D:\Backup") Then
      Directory.CreateDirectory("D:\Backup")
   End If
   Dim MySQL_Connection As SqlConnection = New SqlConnection()
   MySQL_Connection.ConnectionString = "Data Source = LocalHost;Initial Catalog = Datasourcename;Integrated Security  = True"
   MySQL_Connection.Open()
   Dim myCommand As SqlCommand
   myCommand = New SqlCommand(" BACKUP DATABASE [Datasourcename] TO  DISK = N'D:\Backup\Datasourcename_full.bak' WITH FORMAT ", MySQL_Connection)
   myCommand.ExecuteNonQuery()
   myCommand = New SqlCommand(" BACKUP DATABASE [Datasourcename] TO  DISK = N'D:\Backup\Datasourcename_diff.bak' WITH DIFFERENTIAL ,FORMAT ", MySQL_Connection)
   myCommand.ExecuteNonQuery()
   MySQL_Connection.Close()
Catch ex As Exception
   Msgbox(ex.message)                      
End Try

Actually I dont know about the other two formats....

i hate this web site because asking more and more questions repeatedly

hello Poojavb thanks dear,
In your code first three line for created folder by static method,but i need dynamically....pls help me....

this database backup will get created on basis of date....u can also use Application.Startup path or any dynamic path that needs to be created....

 Try
    If Not Directory.Exists("D:\" + Date.Today.ToString("dd.MM.yyyy") + "\Backup") Then
       Directory.CreateDirectory("D:\" + Date.Today.ToString("dd.MM.yyyy") + "\Backup")
    End If
    Dim MySQL_Connection As SqlConnection = New SqlConnection()
    MySQL_Connection.ConnectionString = "Data Source = LocalHost;Initial Catalog = Test;Integrated Security = True"
    MySQL_Connection.Open()
    Dim myCommand As SqlCommand
    myCommand = New SqlCommand(" BACKUP DATABASE [Test] TO DISK =N'D:\" + Date.Today.ToString("dd.MM.yyyy") + "\Backup\Test_full.bak' WITH FORMAT ", MySQL_Connection)
    myCommand.ExecuteNonQuery()
    myCommand = New SqlCommand(" BACKUP DATABASE [Test] TO DISK = N'D:\" + Date.Today.ToString("dd.MM.yyyy") + "\Backup\Test_diff.bak' WITH DIFFERENTIAL ,FORMAT ", MySQL_Connection)
    myCommand.ExecuteNonQuery()
    MsgBox("Backup Successfull")
    MySQL_Connection.Close()
Catch ex As Exception
    MsgBox(ex.Message)
End Try

What if the SQL Server is hosted on a remote system? This code is for local system I hope.....
tnx.

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.