恢复sql不触发
我尝试使用应用程序代码
简单的 sql 命令动态地从备份恢复数据库进行恢复
con.execute("RESTORE FILELISTONLY FROM DISK='c:\old.bak' " & vbcrlf &_
"RESTORE DATABASE newdb " & vbcrlf &_
"FROM DISK='c:\old.bak' " & vbcrlf &_
"WITH MOVE 'newdb' TO 'c:\newdb.mdf', " & vbcrlf &_
"MOVE 'newdb_log' TO 'c:\newdb_log.ldf'")
,但它不会触发,我的意思是没有任何错误 尝试使用 sql profiler 检查它,
RESTORE FILELISTONLY FROM DISK='c:\old.bak'
RESTORE DATABASE newdb
FROM DISK='c:\old.bak'
WITH MOVE 'newdb' TO 'c:\newdb.mdf',
MOVE 'newdb_log' TO 'c:\newdb_log.ldf'
如果我从 sql profiler 运行 sql,它的工作原理
看起来正确,你如何解释这个问题?
Im trying restore database from backup dynamically with application code
simple sql command for restore
con.execute("RESTORE FILELISTONLY FROM DISK='c:\old.bak' " & vbcrlf &_
"RESTORE DATABASE newdb " & vbcrlf &_
"FROM DISK='c:\old.bak' " & vbcrlf &_
"WITH MOVE 'newdb' TO 'c:\newdb.mdf', " & vbcrlf &_
"MOVE 'newdb_log' TO 'c:\newdb_log.ldf'")
but it doesn't fire, i mean no any errors
tried check it with sql profiler and look correctly
RESTORE FILELISTONLY FROM DISK='c:\old.bak'
RESTORE DATABASE newdb
FROM DISK='c:\old.bak'
WITH MOVE 'newdb' TO 'c:\newdb.mdf',
MOVE 'newdb_log' TO 'c:\newdb_log.ldf'
if i run sql from sql profiler its works
how can u explain this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜您使用的连接作为数据库的锁,因此无法恢复。
当你直接运行它时,你还没有。
那这个呢?
或者更改连接字符串中的数据库?
I guess the connection you are using as a lock on the database so it can't restore.
When you run it directly, you haven't.
What about this?
Or changing the database in the connection string?
尝试在运行还原之前杀死还原到的数据库中的所有用户,如果存在与数据库的任何活动连接,还原将失败。 有示例代码说明如何全部执行此操作。
另外,请确保从应用程序调用还原时使用的连接字符串不会连接到还原到的数据库,而是连接到 master 或 msdb 之类的数据库。
Try killing all the users in the database your restoring to before running the restore, a restore will fail if there are any active connections to the db. There is example code of how to do this all over.
Also make sure your connection string used when you call the restore from your application doesn't connect to the db your restoring to, but connects to something like master or msdb.
如果数据库正被其他会话使用,您将无法执行恢复。 确保等待完整 60 秒并查看是否存在任何超时错误。
To perform a restore you are blocked if the database is in use with other sessions. Make sure you wait for a full 60 seconds and see if there are any timeout errors.