2014-07-17 1 views
1

제 문제는 C# 코드를 사용하여 wpf로 데이터베이스를 복원 할 수 없다는 것입니다. 오류는 '서버'DELL/LOCALSERVER '에 대한 복원 실패입니다. 난 그냥 내가 사용하는 코드를 발견하고이 하나 :C# 코드를 사용하여 복원하지 못했습니다.

//를이 코드에 새로운 것을 잘못 모르는 .BAK 파일 경로

private void btnBrowse_Click(object sender, RoutedEventArgs e) 
{ 
    OpenFileDialog ofd = new OpenFileDialog(); 
    ofd.ShowDialog(); 
    txtBackupPath.Text = ofd.FileName; 
} 

private void btnRestore_Click(object sender, RoutedEventArgs e) 
{ 
    ServerConnection con = new ServerConnection(@server, userId, password); 
    Server sqlServerInstance = new Server(con); 
    Restore destination = new Restore(); 
    destination.Action = RestoreActionType.Database; 
    destination.Database = initial_catalog; 
    BackupDeviceItem source = new BackupDeviceItem(txtBackupPath.Text, DeviceType.File); 
    destination.Devices.Add(source); 
    destination.ReplaceDatabase = true; 
    destination.SqlRestore(sqlServerInstance); 
    System.Windows.Forms.MessageBox.Show("The restore of database " + "'H2RPDB'" + " completed sccessfully", "Microsoft SQL Server Management Studio", MessageBoxButtons.OK, MessageBoxIcon.Information); 
    con.Disconnect(); 
} 

를 얻기 위해. 답변 주셔서 감사합니다.

+0

** 어디에서 **이 오류가 발생합니까? –

+0

이 오류는 destination.SqlRestore (sqlServerInstance)에서 발생합니다. – psyche

+0

파일을 여는 서버가 서버 경로라는 사실을 알고 있습니까? 서버 관점에서 볼 때 유효한 경로 여야합니까? 즉'C : \ test.bak'는 서버 C : 디스크에 있습니다. –

답변

1

다행히도 코드는 정확합니다. 시스템에 액세스하려는 경로에 대한 액세스 권한이 없습니다. 그것 이외에, 그것은 작동합니다.

관련 문제