无法还原数据库

编程入门 行业动态 更新时间:2024-10-14 22:13:25
本文介绍了无法还原数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

无法还原数据库

本文发布于:2023-06-01 18:57:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/422854.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!