SQL Server中的备份大型数据库超时错误 [英] Backup big size database time out error in SQL Server

查看:105
本文介绍了SQL Server中的备份大型数据库超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试备份数据库,但出现错误:

I try to backup my database but I get an error:

超时已过期.







备份或还原已中止.

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
The backup or restore was aborted.

这是我的代码,我的数据库最大为20GB.

This is my code, and my database is up to 20GB in size.

string query = "Backup database Testing to disk='C:\Test.bak'"
con.Open();
cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();

如何在C#或查询中更改超时值?

How can I change a timeout value in C# or query?

推荐答案

使用 CommandTimeout属性(

Use CommandTimeout property (Documentation), 0 means no limit.

添加

cmd.CommandTimeout = 0

cmd.CommandTimeout = 0

输入您的代码:

string query = "Backup database Testing to disk='C:\Test.bak'"
con.Open();
cmd = new SqlCommand(query, con);
cmd.CommandTimeout = 0;
cmd.ExecuteNonQuery();
con.Close();

这篇关于SQL Server中的备份大型数据库超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆