PDA

View Full Version : سوال: بکاپ گیری سمت کلاینت



hamidhws
سه شنبه 06 اردیبهشت 1390, 18:44 عصر
با سلام
آیا راهی هست؟

sunn789
چهارشنبه 07 اردیبهشت 1390, 19:55 عصر
علیک سلام
می خواهی از چی BACKUP بکیری?

hamidhws
چهارشنبه 07 اردیبهشت 1390, 20:24 عصر
ضمن تشکر از پاسخگویی شما

می خواهی از چی BACKUP بکیری?
از دیتابیس


راستش از نظر خودم : توی سمت سرور بکاپ بگیرم بعدش فایل بکاپ رو برای کلاینت بفرستم . تا قسمت بکاپ گیری سمت سرور مشکلی ندارم فقط توی ارسال فایل به کلاینت نمیدونم به چه صورته :(

sunn789
چهارشنبه 07 اردیبهشت 1390, 21:10 عصر
احنمالاً سواد من کمه که درست سوال شما رو متوجه نمیشم
خوب مخواهی BACKUP رو به چه صورت سمت کلاینت بفرستی یعنی یک فک فایل BACKUP هز دیتا بیس بفرستی برای یکی از کلاینتها و یا ایتمه یه نحوی بفرستی که کلایت بتونه اونو بخونه و با چه فرمتی قراره کلاینت فایل BACKUP شما رو بخونه(این ها رو پرسیدم تا اگه بتونم کمک کنم و یا اینکه خودم چیزی یاد بگیرم)

hamidhws
چهارشنبه 07 اردیبهشت 1390, 22:02 عصر
چیزی شبیه به دانلود
یعنی وقتی کاربر (ادمین) در سایت روی دکمه backup کلیک کرد یه save dialog box باز بشه که کاربر بتونه مسیر ذخیره سازی رو مشخص کنه بعدش فایل بکاپ براش ارسال بشه و توی درایوی که مشخص کرده ذخیره بشه (فایل دانلود بشه)

sunn789
پنج شنبه 08 اردیبهشت 1390, 00:16 صبح
من این کد رو نوشتم رو رویداد کلید BACKUP
private void btn_Backup_Click(object sender, RoutedEventArgs e)
{
//Connect to the local, default instance of SQL Server.
Server srv = new Server();
//Reference the mySQLdatabasr database.
Database db = default(Database);
db = srv.Databases["SQLCash"];

//Store the current recovery model in a variable.
int recoverymod;
recoverymod = (int)db.DatabaseOptions.RecoveryModel;

//Define a Backup object variable.
Backup bk = new Backup();

//Specify the type of backup, the description, the name, and the database to be backed up.
bk.Action = BackupActionType.Database;
bk.BackupSetDescription = "Full backup of SQLCash";
bk.BackupSetName = "SQLCash Backup";
bk.Database = "SQLCash";

//Declare a BackupDeviceItem by supplying the backup device file name in the constructor, and the type of device is a file.
BackupDeviceItem bdi = default(BackupDeviceItem);
bdi = new BackupDeviceItem(txt_BackUpAddress.Text, Microsoft.SqlServer.Management.Smo.DeviceType.File );

//Add the device to the Backup object.
bk.Devices.Add(bdi);
//Set the Incremental property to False to specify that this is a full database backup.
bk.Incremental = false;

//Set the expiration date.
System.DateTime backupdate = new System.DateTime();
backupdate = new System.DateTime(2006, 10, 5);
bk.ExpirationDate = backupdate;

//Specify that the log must be truncated after the backup is complete.
bk.LogTruncation = BackupTruncateLogType.Truncate;

//Run SqlBackup to perform the full database backup on the instance of SQL Server.
try
{
bk.SqlBackup(srv);
//Inform the user that the backup has been completed.
System.Windows.Forms.MessageBox.Show("تهیه نسخه پشتیبان با موفقیت به انجام رسید.", "نسخه پشتیبان", MessageBoxButtons.OK,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.RightAlign | System.Windows.Forms.MessageBoxOptions.RtlReading) ;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("در آدرس تهیه نسخه پشتیبان دقت نمایید\n" + ex.ToString());
}
//Remove the backup device from the Backup object.
bk.Devices.Remove(bdi);


}

hamidhws
پنج شنبه 08 اردیبهشت 1390, 12:36 عصر
ضمن تشکر و سپاس از شما دوست عزیز
در واقع بوسیله این کد بکاپ روی سیستم کلاینت گرفته میشه یا روی سرور؟

با تشکر دوباره

sunn789
شنبه 10 اردیبهشت 1390, 00:42 صبح
اول یه Text Box میزارم برا اینکه ادرس BACK up رو از کاربر بپرسه که کجا ذخیره کنه و زمانی که روی دکمه تهیه پشتیبان کلیک میکنه این کد اجرا میشه و در ادرسی که کاربر داده ذخیره میشه

hamidhws
شنبه 10 اردیبهشت 1390, 13:22 عصر
من این کد رو نوشتم رو رویداد کلید BACKUP
private void btn_Backup_Click(object sender, RoutedEventArgs e)
{
//Connect to the local, default instance of SQL Server.
Server srv = new Server();
//Reference the mySQLdatabasr database.
Database db = default(Database);
db = srv.Databases["SQLCash"];

//Store the current recovery model in a variable.
int recoverymod;
recoverymod = (int)db.DatabaseOptions.RecoveryModel;

//Define a Backup object variable.
Backup bk = new Backup();

//Specify the type of backup, the description, the name, and the database to be backed up.
bk.Action = BackupActionType.Database;
bk.BackupSetDescription = "Full backup of SQLCash";
bk.BackupSetName = "SQLCash Backup";
bk.Database = "SQLCash";

//Declare a BackupDeviceItem by supplying the backup device file name in the constructor, and the type of device is a file.
BackupDeviceItem bdi = default(BackupDeviceItem);
bdi = new BackupDeviceItem(txt_BackUpAddress.Text, Microsoft.SqlServer.Management.Smo.DeviceType.File );

//Add the device to the Backup object.
bk.Devices.Add(bdi);
//Set the Incremental property to False to specify that this is a full database backup.
bk.Incremental = false;

//Set the expiration date.
System.DateTime backupdate = new System.DateTime();
backupdate = new System.DateTime(2006, 10, 5);
bk.ExpirationDate = backupdate;

//Specify that the log must be truncated after the backup is complete.
bk.LogTruncation = BackupTruncateLogType.Truncate;

//Run SqlBackup to perform the full database backup on the instance of SQL Server.
try
{
bk.SqlBackup(srv);
//Inform the user that the backup has been completed.
System.Windows.Forms.MessageBox.Show("تهیه نسخه پشتیبان با موفقیت به انجام رسید.", "نسخه پشتیبان", MessageBoxButtons.OK,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.RightAlign | System.Windows.Forms.MessageBoxOptions.RtlReading) ;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("در آدرس تهیه نسخه پشتیبان دقت نمایید\n" + ex.ToString());
}
//Remove the backup device from the Backup object.
bk.Devices.Remove(bdi);


}

سلام دوست عزیز
برای کد بالا از چه namespace هایی باید استفاده کنم؟

sunn789
شنبه 10 اردیبهشت 1390, 17:19 عصر
سلام دوست عزیز
برای کد بالا از چه namespace هایی باید استفاده کنم؟

using System;
using System.Windows;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;