Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI
I was download this code

SQL Server 2005 Database Backup and Restore using C# and .NET 2.0[^]

when I use Restore code in my project can't restore (the message:restore to database ... fail)
but backup code is ok.
all of refrence are completely;

what dio I do? whould you please help me?
Posted

Make sure all connections to the database are closed before doing a restore.
A restore wont happen unless all existing connections are closed.
 
Share this answer
 
Comments
sachin10d 12-Sep-11 7:52am    
make connection using master database. Then only restore will work
Immediate solution to identify the root cause for this problem, would be to introduce try.. catch block as:

C#
public void RestoreDatabase(String databaseName, String filePath,
       String serverName, String userName, String password,
       String dataFilePath, String logFilePath)
{
  try
  {
    Restore sqlRestore = new Restore();
    ......
  }
  catch (Exception ex)
  {
    Console.WriteLine("Restore error is: " + ex.Message);
  }
}


Mostly, the error might be because of few SQL specific restriction for RESTORE on Transact-SQL, as below:

A restore scenario in SQL Server is the process of restoring data from one or more backups and then recovering the database. The supported restore scenarios depend on the recovery model of the database and the edition of SQL Server.

* To set Restore object properties, users must have CREATE DATABASE permission on the server, or be a member of sysadmin or dbcreator fixed server roles, or be a member of db_owner fixed database role.

* Online restore is allowed only in SQL Server 2005 Enterprise Edition and later versions.
 
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