کد مربوط به گرفتن پشیبان از بانک و بازیابی آن

بپرسید

0

{{ digitTrunc(content.likes) }}

سلام ، کسی هست کمک کنه خطای این کد که مربوط به گرفتن backup , restorاز بانک sql 2008 توی c# باشه:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
using Microsoft.SqlServer.Management.Smo;

namespace mali_navid_sadghin
{
    class prog
    {
        static void Main(string[] args)
        {
            BackupDB(@"C:\Temp\Test.bak");
            RestoreDB(@"C:\Temp\Test.bak", "Test_Restore");
        }

        public static void BackupDB(string backupDestinationFilePath)
        {
            try
            {
                Console.WriteLine("Backup operation started");
                Backup backup = new Backup();
                //Set type of backup to be performed to database
                backup.Action = BackupActionType.Database;
                backup.BackupSetDescription = "BackupDataBase description";
                //Set the name used to identify a particular backup set.
                backup.BackupSetName = "Backup";
                //specify the name of the database to back up
                backup.Database = "TEST";
                //Set up the backup device to use filesystem.
                BackupDeviceItem deviceItem = new BackupDeviceItem(backupDestinationFilePath, DeviceType.File);
                backup.Devices.Add(deviceItem);

                // Setup a new connection to the data server
                ServerConnection connection = new
    ServerConnection(@"SERVER_NAME");
                // Log in using SQL authentication
                connection.LoginSecure = false;
                connection.Login = "testuser";
                connection.Password = "testuser";
                Server sqlServer = new Server(connection);
                //Initialize devices associated with a backup operation.
                backup.Initialize = true;
                backup.Checksum = true;
                //Set it to true to have the process continue even
                //after checksum error.
                backup.ContinueAfterError = true;
                //Set the backup expiry date.
                backup.ExpirationDate = DateTime.Now.AddDays(3);
                //truncate the database log as part of the backup operation.
                backup.LogTruncation = BackupTruncateLogType.Truncate;
                //start the back up operation
                backup.SqlBackup(sqlServer);
                Console.WriteLine("Backup operation succeeded");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Backup operation failed");
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }

        public static void RestoreDB(string backUpFilePath, string databaseName)
        {
            try
            {
                Console.WriteLine("Restore operation started");
                Restore restore = new Restore();
                //Set type of backup to be performed to database
                restore.Database = databaseName;
                restore.Action = RestoreActionType.Database;
                //Set up the backup device to use filesystem.         
                restore.Devices.AddDevice(backUpFilePath, DeviceType.File);
                //set ReplaceDatabase = true to create new database
                //regardless of the existence of specified database
                restore.ReplaceDatabase = true;
                //If you have a differential or log restore to be followed,
                //you would specify NoRecovery = true
                restore.NoRecovery = false;
                //if you want to restore to a different location, specify
                //the logical and physical file names
                restore.RelocateFiles.Add(new RelocateFile("Test",
    @"C:\Temp\Test.mdf"));
                restore.RelocateFiles.Add(new RelocateFile("Test_Log",
    @"C:\Temp\Test_Log.ldf"));
                ServerConnection connection = new
    ServerConnection(@"SERVER_NAME");
                //my SQL user doesnt have sufficient permissions,
                //so i am using my windows account
                connection.LoginSecure = true;
                //connection.LoginSecure = false;
                //connection.Login = "testuser";
                //connection.Password = "testuser";
                Server sqlServer = new Server(connection);
                //SqlRestore method starts to restore database           
                restore.SqlRestore(sqlServer);
                Console.WriteLine("Restore operation succeeded");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Restore operation failed");
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
    }
}

دوره های شبکه، برنامه نویسی، مجازی سازی، امنیت، نفوذ و ... با برترین های ایران

پاسخ ها به این سوال

پاسخ ها به این سوال

{{ digitTrunc(post.likes) }}

این پست در تاریخ {{ dateString(new Date(post.deleteDate)) }} توسط {{ post.deletedByUser }} حذف شده است.

دلیل حذف: {{ post.deleteReason ?? 'نامشخص' }}

{{ err }}
{{ post.userAchivements.rhodiumAchievements }}
{{ post.userAchivements.platinumAchievements }}
{{ post.userAchivements.goldAchievements }}
{{ post.userAchivements.silverAchievements }}
{{ post.userAchivements.bronzeAchievements }}
{{ timeSince(new Date(post.date)) }} قبل

برای ثبت پاسخ خود در وب سایت وارد حساب کاربری خود شوید
قابلیت ارسال مطلب توسط مدیریت سایت غیر فعال شده است