【问题标题】:How to change timeout for connection_instance.Open() command?如何更改 connection_instance.Open() 命令的超时时间?
【发布时间】:2012-12-18 15:30:07
【问题描述】:

伙计们!

我正在使用实体框架(但实际上并不重要)和多个数据库(ObjectContexts)。其中一台sql server有额外的数据,是可选的,有时会离线。

当我在服务器脱机时尝试处理任何命令的异常时,我应该在 connection_instance.Open() 命令运行时等待 60 秒,这会给我带来异常:

与服务器建立连接时出错。 连接到 SQL Server 2005 时,此故障可能是由 事实上,在默认设置下 SQL Server 不允许远程 连接。 (提供者:命名管道提供者,错误:40 - 无法 打开与 SQL Server 的连接)

我能否以某种方式将此超时时间从 60 秒更改为 5 秒的另一个值?顺便说一句,我的实体框架超时连接是2秒,但它忽略了。

看起来这个超时设置为整个系统(可能在 Windows 寄存器中)。我尝试通过 SQL Management Studio 连接到这个 sql server,它也尝试连接 60 秒,但得到了同样的异常。

那么,有没有办法改变这个超时值呢?或者也许还有另一种快速检查 sqlserver 状态的方法?

【问题讨论】:

  • ObjectContext.CommandTimeout 有效吗? /// /// 获取或设置所有对象上下文操作的超时值,以秒为单位。空值表示将使用基础提供程序的默认值。 /// /// /// /// 一个 值,它是超时值,以秒为单位。 /// /// 超时值小于0。 public int?命令超时

标签: sql-server entity-framework


【解决方案1】:

ObjectContext.CommandTimeout 有效吗?

 /// <summary>
/// Gets or sets the timeout value, in seconds, for all object context operations. A null value indicates that the default value of the underlying provider will be used.
/// </summary>
/// 
/// <returns>
/// An <see cref="T:System.Int32"/> value that is the timeout value, in seconds.
/// </returns>
/// <exception cref="T:System.ArgumentException">The timeout value is less than 0. </exception>
public int? CommandTimeout

【讨论】:

    猜你喜欢
    • 2011-01-20
    • 2010-11-14
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    相关资源
    最近更新 更多