2012-12-17 45 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