Immediate solution to identify the root cause for this problem, would be to introduce try.. catch block as:
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.