无法还原数据库 [英] Unable to restore database
本文介绍了无法还原数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Restore restore = new Restore();
restore.Database = "bw_restore";
restore.Action = RestoreActionType.Database;
restore.Devices.AddDevice(@"C:\SQLBackup\bw.bak",DeviceType.File);
restore.ReplaceDatabase = true;
restore.NoRecovery = false;
restore.RelocateFiles.Add(new RelocateFile("bw",@"C:\SQLBackup\bw.mdf"));
restore.RelocateFiles.Add(new RelocateFile("bw_Log",@"C:\SQLBackup\bw_Log.ldf"));
ServerConnection connection = new ServerConnection(@"Data Source=NILE-ROSE\SQLEXPRESS;User ID=sa;Password=welcome@123;Initial Catalog=bw_restore;");
connection.LoginSecure = true;
//connection.LoginSecure = false;
//connection.Login = "testuser";
//connection.Password = "testuser";
Server sqlServer = new Server(connection);
//MessageBox.Show(sqlServer.ToString());
restore.SqlRestore(sqlServer);
MessageBox.Show("Restored Successfully");
出现类似错误
在Microsoft.SqlServer.SmoExtended.dll
Getting Error Like
An unhandled exception of type ''Microsoft.SqlServer.Management.Smo.FailedOperationException'' occurred in Microsoft.SqlServer.SmoExtended.dll
推荐答案
sqry =使用主机"中发生了类型为"Microsoft.SqlServer.Management.Smo.FailedOperationException"的未处理异常&vbCrLf&还原数据库"&数据库名称&从磁盘="&保留数据库的路径&"''带替换,将数据库名称"移至"&mdf +数据库名称&".mdf的路径",将数据库名_log"移动到"和ldf的路径+数据库名和"_log.ldf""和vbCrLf和"SET LOCK_TIMEOUT 3000"
''MsgBox(SQL)
da =新的SqlDataAdapter(sqry,mycon)
da.SelectCommand.ExecuteNonQuery()
异常捕获
结束尝试
sqry = "use master" & vbCrLf & "RESTORE DATABASE " & databasename & " FROM DISK = ''" & path where database is kept & "'' WITH replace,move ''databasename '' to ''" & path for mdf + databasename & ".mdf'', MOVE ''databasename _log'' to ''" & path for ldf + databasename & "_log.ldf''" & vbCrLf & "SET LOCK_TIMEOUT 3000"
'' MsgBox(SQL)
da = New SqlDataAdapter(sqry, mycon)
da.SelectCommand.ExecuteNonQuery()
Catch ex As Exception
End Try
这篇关于无法还原数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文