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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mahesh ChandRank #1 · 393.3K reputationPosted Sep 3, 2011, 10:23 PM EDT
BACKUP DATABASE { database_name | @database_name_var } TO
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 4, 2011, 10:23 PM EDT
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);
}
Vilas GiteRank #951 · 2.1K reputationPosted Sep 4, 2011, 10:40 PM EDT
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"
Guruparan Giritharan20 reputationPosted Sep 5, 2011, 9:13 AM EDT
Others are really advanced for me.
-Guru-
Mahesh ChandRank #1 · 393.3K reputationPosted Sep 5, 2011, 9:16 AM EDT
I did not know Microsoft.SqlServer.Management; and related namespace can be used for this purpose. Nice! Now I have something new to learn.