2012-12-17 30 views
2

伙计!如何更改connection_instance.Open()命令的超时时间?

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

当我试图处理上的任何命令例外,当服务器脱机,如果我要等待60秒connection_instance.Open()命令操作,让我异常:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

我可以以某种方式改变这种超时时间从60秒到5秒另一个值?顺便说一下,我的实体框架超时连接是2秒,但它忽略。

它看起来像这个超时设置为整个系统(可能在Windows注册表中)。我尝试通过SQL Management Studio连接到这个SQL服务器,并且尝试连接60秒,并且在得到相同的异常之后。

那么,有什么办法可以改变这个超时值吗?或者也许thera另一种快速检查sqlserver状态的方法?

+0

ObjectContext.CommandTimeout是否工作? ///

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

回答

0

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 
+0

不幸的是,没有 – DanTheMan