Community discussion forum

How to take Backup from SQL database

Tags: India
  • 3 years ago

    Hi friends

    I want to know how take backup from SQL Database through VB.Net coding. The backup method is two way one is Table by table and procedure. And the second method is DUMP file. Also i want to know how to import datas of the two methods (Table by table, DUMP file) into SQL Database .

    Please give me a advise and also coding if u have.

    Very Urgent

    Regards

    Hari K

  • 3 years ago

    Hi, If you want this done server side then use the "BACKUP DATABASE 'dbnamehere' TO DISK ='C:\MyBackup.BAK'" as the commad text for you command object (sql or oleDb).

    If you want this done locally on the client machine then I suggest you use datasets & then save them to xml.

    Dim cnn As SqlClient.SqlConnection = New SqlClient.SqlConnection("the connection string")
    Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from MyTable", cnn)
    Dim ds As DataSet = New DataSet

        da.Fill(ds)

        ds.WriteXml("File Name here, eg. C:\backup
    MyTable.xml")

        da.Dispose()
        da = Nothing

        cnn.Dispose()
        cnn = Nothing


    As for restoring from the xml files if this was really necessary & you know you are the only one accessing the database then:

     you could use the dataset.ReadXml("filename.xml") function

    1. validate that the data is OK & make sure you have a good connecting.
    2. delete all data from the table
    3. loop through ds.tables(0).rows()  inserting the data back into the database or into another dataset/table & then use the data adapter to update the database again.

    Of course you will need a way of keeping users out while this process is hapening (unless this is not a mulit user senario).

    Hope this is of some help.
































  • 3 years ago

    Hi dtth555

     Thanks for ur reply

     Now i am using first method as u above mentioned. Actually this method backup and save the backup datas into Server not in my Local system. I think the second method(XML) is not suitable for me because i want to take a backu for  Database not a single table. In my database having more that 100 tables and more that 100 procedures. Is it possible to take a backup in a first or second method.

    Actually i need backup file in to my local system. What can i do?

    And one more thing is After i took a backup i want to restore into another database that mean

    Backup db1 to disk "c:\back"

    Restore Database db2 From "c:\back" ' in this time the physical directory of the current database is needed for restore. How to take the physical directory. that is mdf and ldf File path.

    Regard

    Hari K

  • 3 years ago

    did you try using sqldmo? have a look here

    http://www.codersource.net/csharp_sqldmo_sqlserver.aspx

    you can use it for both backup and restore.

    However I don't think you can backup to a remote machine unless you have your local machine's drive mapped on the server you're taking the backup from.

     

  • 3 years ago

    Hi balkanski

     Actually i need for VB.Net

     but u r givcing for C# reference.

    Actually i solved my problem before seen ur reference.

    Regards

    Hari K

  • 3 years ago

    Dear hari

    U can find it in http://www.aspfree.com/c/a/VB.NET/Simple-BackupRestore-Utility-With-SQLDMO-Using-VBNET/

     

    Hope this may help u

     

    Sai

  • 9 months ago
    Hi there..! I want to take backup on basis of specific data. can u suggest me how to do that,
  • 9 months ago
    Firstly you can build a procedure in sql database then which can backup your data and execute that procedure from .net. if you need any suggestion or support you can visit [outsource and offshore software development nepal](http://www.meroblog.net/outsourcing-software-development-offshore-software-dveloper-nepal.html)

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback