是否可以仅通过调用 Open() 来关闭或断开 SqlConnection 重新连接?
Can be closed or broken SqlConnection reconnected simply by calling Open()?
在我的方法中,如果我发现我收到的连接 (System.Data.SqlClient.SqlConnection
)
State = Closed
或者
State = Broken
以下哪种做法是正确的?
调用Open()
重新连接并继续执行后续语句。 (当然我也可以给Open()
预先设置的重试次数。)
将无法恢复的连接丢弃并获得全新的连接。
(如果这些方法相同,我更喜欢第一种,因为它更容易实现。)
(ConnectionState.Broken) The connection to the data source is broken. This can occur only after the connection has been opened. A connection in this state may be closed and then re-opened. (This value is reserved for future versions of the product.)
即您可以使用 Open() 关闭并重新打开连接。如果 State 关闭,你应该抛出异常
在我的方法中,如果我发现我收到的连接 (System.Data.SqlClient.SqlConnection
)
State = Closed
或者State = Broken
以下哪种做法是正确的?
调用
Open()
重新连接并继续执行后续语句。 (当然我也可以给Open()
预先设置的重试次数。)将无法恢复的连接丢弃并获得全新的连接。
(如果这些方法相同,我更喜欢第一种,因为它更容易实现。)
(ConnectionState.Broken) The connection to the data source is broken. This can occur only after the connection has been opened. A connection in this state may be closed and then re-opened. (This value is reserved for future versions of the product.)
即您可以使用 Open() 关闭并重新打开连接。如果 State 关闭,你应该抛出异常