0

SQL Server 2008、Visual Studio 08 和 C#

任务是在多台服务器上创建相同的数据库。如果只有两个或三个表,我会手动完成,但数据库中有 50 多个表..

所以我想为什么不创建备份并在需要的地方恢复备份文件

错误

该文件正在使用中!(虽然没有使用备份,但错误是说实际的数据库正在使用中!是的,每次我想在其他服务器上恢复备份时,我都无法关闭服务器!)

那我该怎么办,请给出你的想法

还要注意

无论你说什么都应该可以使用 SMO 对象来实现

谢谢你

4

3 回答 3

1

[修订 - 我需要学习更好地阅读]

I'm not certain about SMO Objects, but given that SMO can work like other SQL Server functionality, what we do for our project is to use a Database Project that deploys to our servers automatically. This probably requires Database Edition (VS 2008) or higher...premium in 2010. If you have that, it's definitely a nice option to create a DB project. Then, you just set it up to do a schema compare (and you might be able to do a data compare as well if you need that...?) during deployment. Auto-deployment is harder to setup initially, but once it's setup, you're good to go with single click deployments...we use TFS to deploy right now, but I hear good things about TeamCity:

http://www.jetbrains.com/teamcity/

Kevin

于 2010-10-20T21:01:53.560 回答
0

在运行还原之前,您可以运行存储过程“sp_who2”,它将列出与数据库的当前连接。如果您仍然要覆盖数据库,那么对于每个连接,您都可以发出“kill”来强制关闭连接。

我还记得在 Sql 管理工作室中使用恢复 GUI 时有一些“关闭所有现有连接”选项。

于 2010-10-20T20:47:24.133 回答
0

使用 usp_killDBConnections @DBName=''DbName''

在运行还原操作之前。该命令将在还原之前终止所有数据库连接,这在还原期间很重要。

于 2010-10-20T20:47:30.007 回答