I’m trying to restore a database by using the following code
string Restore = @"RESTORE DATABASE [" + dbname+ "] FROM DISK = N'" + filePath + "' WITH REPLACE, FILE = 1, NOUNLOAD, STATS = 10";
SqlCommand RestoreCmd = new SqlCommand(Restore, con);
RestoreCmd.ExecuteNonQuery();
it returns me a timeout expired error, I have set connect timeout=300 in the connectionstring
but by running only the t-sql script
RESTORE DATABASE [dbname] FROM DISK = N’filepath’ WITH REPLACE, FILE = 1, NOUNLOAD, STATS = 10
it works fine
what should i do to fix this?
Set the CommandTimeout property of you RestoreCmd like so: