本文介绍了在sql server2012中恢复数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将数据库从sqlserver 2008R2恢复到sqlserver 2012?
Is it possible to restore a database from sqlserver 2008R2 to sqlserver 2012?
推荐答案
using(SqlConnection sqlCon = new SqlConnection(ConnectionString))
{
StringBuilder sb = new StringBuilder();
//e.g. RESTORE DATABASE [CompuData] FROM DISK = N'D:\Backup\Backup_05_09_2012.bak' WITH FILE = 2, MOVE N'DBName' TO N'D:\DataBase\DBName.mdf', MOVE N'DBName_log' TO N'D:\DataBase\DBName_log.ldf', NOUNLOAD, REPLACE, STATS = 1
sb.AppendFormat(@"RESTORE DATABASE [{0}] FROM DISK = N'{1}' WITH FILE = {2}, MOVE N'{3}' TO N'{4}', MOVE N'{5}' TO N'{6}', NOUNLOAD, REPLACE, STATS = 1",
DBNameTo, BackupFilePath, Position, DBNameFrom, MdfFileName, LogFileName, LdfFileName);
SqlCommand sqlCmd = new SqlCommand(sb.ToString(), sqlCon);
sqlCmd.CommandTimeout = 10000;
sqlCmd.ExecuteNonQuery();
sqlCon.Close();
}
这篇关于在sql server2012中恢复数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!