Posted on: 9/10/2013 1:25:04 PM | Views : 901

I have been using this code for about 2 years to restore 2008 r2 backup to 2008 r2 and it works every time. I am now trying to use the same code to restore from 2008 r2 backup to 2012 localdb and it fails every time. The error message is below. Not only does the restore fail, it leaves my current database in 'recovery pending' state, and is unusable. I am using c# and this must all be done programmatically with no user or DBA involvement. Can you help me get this thing back on track?

using(var connection = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = String.Format("Alter Database {0} SET SINGLE_USER With ROLLBACK IMMEDIATE", dbName); cmd.CommandType = CommandType.Text; cmd.Connection = connection; connection.Open(); cmd.ExecuteNonQuery(); Sq ...

Go to the complete details ...