简体   繁体   English

从代码还原数据库备份?

[英]Restore Database backup from code?

I have an application extension which I need to test. 我有一个需要测试的应用程序扩展。 Part of the extension applies some updates to the application database schema (via the applications API). 扩展的一部分(通过应用程序API)将一些更新应用于应用程序数据库模式。 i want to test that given version 1 of the application when my class is run the schema becomes v1.1 and that certain queries for items which should exist in 1.1 return correctly. 我想测试在运行我的类时给定应用程序的版本1,该架构将变为v1.1,并且某些应在1.1中存在的项目查询正确返回。 I have backup of the database at schema v1.0 and what I would like to do in my tests is: 我已在架构v1.0中备份了数据库,我想在测试中做的是:

1/ restore the database from a backup 1 /从备份还原数据库

2/ call the code which does the update 2 /调用执行更新的代码

3/ call several methods which verify that the schema updates have succeeded 3 /调用几种方法来验证架构更新是否成功

4/restore the database from a backup 4 /从备份还原数据库

Are there classes I can use to do this restore in my c# code, or do I have to execute the command in shell process? 我可以在C#代码中使用哪些类来执行此还原,还是必须在Shell进程中执行命令?

If you are uysing SQL Server, you could use the SQL Management objects (SMO) 如果您使用的是SQL Server,则可以使用SQL管理对象(SMO)

An example can be found here 可以在这里找到一个例子

Kindness, 善良,

Dan

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM