Skip to content

Commit cf2cead

Browse files
committed
Forbids to use Session.SelectStorageNode for sessions with opened connection
1 parent 04a5ee1 commit cf2cead

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Orm/Xtensive.Orm/Orm/Providers/StorageDriver.Operations.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ private sealed class InitializationSqlExtension
2323

2424
public void ApplyNodeConfiguration(SqlConnection connection, NodeConfiguration nodeConfiguration)
2525
{
26-
if (nodeConfiguration.ConnectionInfo!=null)
26+
if (connection.State != ConnectionState.Closed) {
27+
throw new InvalidOperationException(Strings.ExCannotApplyNodeConfigurationSettingsConnectionIsInUse);
28+
}
29+
30+
if (nodeConfiguration.ConnectionInfo != null) {
2731
connection.ConnectionInfo = nodeConfiguration.ConnectionInfo;
32+
}
2833

29-
if (!string.IsNullOrEmpty(nodeConfiguration.ConnectionInitializationSql))
34+
if (!string.IsNullOrEmpty(nodeConfiguration.ConnectionInitializationSql)) {
3035
SetInitializationSql(connection, nodeConfiguration.ConnectionInitializationSql);
36+
}
3137
}
3238

3339
public SqlConnection CreateConnection(Session session)

Orm/Xtensive.Orm/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Orm/Xtensive.Orm/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,4 +3446,7 @@ Error: {1}</value>
34463446
<data name="ExKeyBelongsToDifferentStorageNode" xml:space="preserve">
34473447
<value>The Key belongs to different storage node.</value>
34483448
</data>
3449+
<data name="ExCannotApplyNodeConfigurationSettingsConnectionIsInUse" xml:space="preserve">
3450+
<value>Cannot apply node configuration: connection is already in use. This may happen if the session was open asynchronously. Use new StorageNode.OpenSession(...) API instead of Session.SelectStorageNode(...)</value>
3451+
</data>
34493452
</root>

0 commit comments

Comments
 (0)