Hi
I need to know whether it is possible to create an application using c sharp that can make back ups of the database(ms sql server) if so can you please provide any article links to articles or sample source codes
Thaks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mahesh ChandPosted Sep 4, 2011, 2:23 AM
BACKUP DATABASE { database_name | @database_name_var } TO
Mahesh ChandPosted Sep 5, 2011, 1:16 PM
I did not know Microsoft.SqlServer.Management; and related namespace can be used for this purpose. Nice! Now I have something new to learn.
Guruparan GiritharanPosted Sep 5, 2011, 1:13 PM
Others are really advanced for me.
-Guru-
Vilas GitePosted Sep 5, 2011, 2:40 AM
Hi Guru!
Refer this thread for your post…
http://social.msdn.microsoft.com/Forums/en-US/sqlsmoanddmo/thread/7690214d-4cba-4757-9956-05f0ca408db5/
Thanks!
--------------------------------------------------------------------
If this reply helps your post…then check "This is correct answer"
Prabhu RajaPosted Sep 5, 2011, 2:23 AM
Try this, first import following .net classes
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Management;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
Backup Function:
public void BackupDatabase(String databaseName, String userName, String password, String serverName, String destinationPath)
{
Backup sqlBackup = new Backup();
sqlBackup.Action = BackupActionType.Database;
sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
sqlBackup.BackupSetName = "Archive";
sqlBackup.Database = databaseName;
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlBackup.Initialize = true;
sqlBackup.Checksum = true;
sqlBackup.ContinueAfterError = true;
sqlBackup.Devices.Add(deviceItem);
sqlBackup.Incremental = false;
sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
sqlBackup.FormatMedia = false;
sqlBackup.SqlBackup(sqlServer);
}