我正在尝试使用以下代码恢复数据库
string Restore = @"RESTORE DATABASE [" + dbname+ "] FROM DISK = N'" + filePath + "' WITH REPLACE, FILE = 1, NOUNLOAD, STATS = 10";
SqlCommand RestoreCmd = new SqlCommand(Restore, con);
RestoreCmd.ExecuteNonQuery();
它返回一个超时过期错误,我在connectionstring中设置了connect timeout = 300
但是只运行t-sql脚本 RESTORE DATABASE [dbname] FROM DISK = N'filepath'WRE REPLACE,FILE = 1,NOUNLOAD,STATS = 10 它工作正常
我该怎么做才能解决这个问题?
答案 0 :(得分:1)
设置RestoreCmd的CommandTimeout属性,如下所示:
RestoreCmd.CommandTimeout = 300;