Click here to Skip to main content
15,916,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to restore a database from sqlserver 2008R2 to sqlserver 2012?
Posted

1 solution

Yes u can Try it

C#
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();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900