SQL 2005 데이터베이스를 * .bak 파일로 백업해야합니다 (C# 사용). 그 파일에서 동일한 정확한 서버에 새로운 데이터베이스로 복원하려고합니다.SQL 데이터베이스 백업 및 복원
백업이 제대로 작동하고 내 C# 코드가 복원 방법을 호출하고 마침내 "시간 초과"될 때까지 작동하는 것처럼 보입니다. 나는 "innerExceptions"를 검사하고 RESTORE가이를 90 %로 만든 다음 예외를 반환한다는 것을 나타냅니다.
다음은 BACKUP 및 RESTORE에 사용하는 코드입니다.
누군가 내가 잘못 가고 있다는 것을 알려주실 수 있습니까? 내가 설정할 수있는 시간 초과 매개 변수 여야합니다. 그러나 그 매개 변수가 무엇인지 또는 수행하는 방법을 알지 못합니다.
public class JRBackupRestoreDB
{
public static 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);
}
public static void RestoreDatabase(String databaseName, String filePath,
String serverName, String userName, String password,
String dataFilePath, String logFilePath)
{
Restore sqlRestore = new Restore();
BackupDeviceItem deviceItem = new BackupDeviceItem(filePath, DeviceType.File);
sqlRestore.Devices.Add(deviceItem);
sqlRestore.Database = databaseName;
ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlRestore.Action = RestoreActionType.Database;
String dataFileLocation = dataFilePath + databaseName + ".mdf";
String logFileLocation = logFilePath + databaseName + "_Log.ldf";
db = sqlServer.Databases[databaseName];
RelocateFile rf = new RelocateFile(databaseName, dataFileLocation);
System.Data.DataTable logicalRestoreFiles = sqlRestore.ReadFileList(sqlServer);
sqlRestore.RelocateFiles.Add(new RelocateFile(logicalRestoreFiles.Rows[0][0].ToString(), dataFileLocation));
sqlRestore.RelocateFiles.Add(new RelocateFile(logicalRestoreFiles.Rows[1][0].ToString(), logFileLocation));
sqlRestore.SqlRestore(sqlServer);
db = sqlServer.Databases[databaseName];
db.SetOnline();
sqlServer.Refresh();
}
}
, 당신은 그냥이에 저장 프로 시저를 만들 수는 MDF를 전달하고 LDF 경로. – clamchoda
나는 타임 아웃 매개 변수를 추가하고 지금 시도했다. 저장 프로 시저가 성능면에서보다 효율적입니까? – dellbingham