CSharp/C# >> how to take database backup

by Abhijit » Sun, 07 Sep 2008 21:35:27 GMT

hi
i am using vb.net2005
i want to take daily backup from application
and attach that daily backup if any data loss

CSharp/C# >> how to take database backup

by Arne Vajh » Sun, 07 Sep 2008 22:50:09 GMT



Read http://msdn.microsoft.com/en-us/library/ms186865 (SQL.90).aspx
and http://msdn.microsoft.com/en-us/library/ms190372 (SQL.90).aspx, if
it is not clear then ask more specific.

Arne

CSharp/C# >> RE: how to take database backup

by TW9ydGVuIFdlbm5ldmlrIFtDIyBNVlBd » Mon, 08 Sep 2008 13:48:08 GMT


You need to use Microsoft.SqlServer.Management objects

using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
...
using (SqlConnection conn = new SqlConnection(connString))
{
ServerConnection serverConnection = new ServerConnection(conn);
Server server = new Server(serverConnection);
Backup backup = new Backup();
backup.SqlBackup(server);
}

Translate to vb.net as necessary (PS you did as a C# group :P )

You will most likely have to set several properties on the Backup object
before calling SqlBackup, as well as subscribe to events.

--
Happy Coding!
Morten Wennevik [C# MVP]

Similar Threads

1. Optimized & fastest way of taking backup & restoring database through C# code

BACKUP/RESTORE,sp_detach_db, sp_attach_db system stored procedures.For 
details please refer to the BOL



"Pankaj Jain" < XXXX@XXXXX.COM > wrote in message 
news: XXXX@XXXXX.COM ...
> Hi ,
>
> Can any one tell me the Optimized  & fastest way of taking backup & 
> restoring my database  that is in SQL Server through  C# code.
> Currently I am using   SQLDMO .Is there any Better approach of achiving 
> the same?
>
> Regards
> Pankaj Jain
> 


2. Taking a backup from C++ program. - Oracle

3. Taking backup to SD Card

Hi,
 I am writing an appliction to take backup of data to SD Card. I want
to know the API's used to retrive information like SD Card  Name,
available space and API's to copy files from flash to SD Card.

Thanks in advance.

4. SQL SERVER 2005 - Backup/Restore database . - CSharp/C#

5. Backup database

Dear sirs
I`m using MS-SQL server to make my database\and connect to 
it using C#
is there any way that I can make a backup to my database
using C#

thanks
Mohammed

6. How to check Backup of SQL Server Database - CSharp/C#

7. Reapair and backup an Access Database

Hi everyone,

I am writing an application that connects to an Access Database. I need, in
a timely basis, to repair, compact and backup the database.

I believe there a way to do it without using Access Object Model.

Can anyone give me a hint?

Thanks, from Spain


8. Backup-Restore SQL server database using C# - CSharp/C#