@@ -9,6 +9,12 @@ public sealed class YdbConnection : DbConnection
99{
1010 private static readonly YdbConnectionStringBuilder DefaultSettings = new ( ) ;
1111
12+ private static readonly StateChangeEventArgs ClosedToOpenEventArgs =
13+ new ( ConnectionState . Closed , ConnectionState . Open ) ;
14+
15+ private static readonly StateChangeEventArgs OpenToClosedEventArgs =
16+ new ( ConnectionState . Open , ConnectionState . Closed ) ;
17+
1218 private bool _disposed ;
1319
1420 private YdbConnectionStringBuilder ConnectionStringBuilder { get ; set ; }
@@ -84,18 +90,20 @@ public override async Task OpenAsync(CancellationToken cancellationToken)
8490
8591 try
8692 {
87- Session = await PoolManager . GetSession ( ConnectionStringBuilder ) ;
93+ Session = await PoolManager . GetSession ( ConnectionStringBuilder , cancellationToken ) ;
8894 }
8995 catch ( Exception e )
9096 {
9197 throw e switch
9298 {
9399 Driver . TransportException transportException => new YdbException ( transportException . Status ) ,
94100 StatusUnsuccessfulException unsuccessfulException => new YdbException ( unsuccessfulException . Status ) ,
95- _ => new YdbException ( "Cannot get session" , e )
101+ _ => e
96102 } ;
97103 }
98104
105+ OnStateChange ( ClosedToOpenEventArgs ) ;
106+
99107 ConnectionState = ConnectionState . Open ;
100108 }
101109
@@ -118,6 +126,8 @@ public override async Task CloseAsync()
118126 await LastTransaction . RollbackAsync ( ) ;
119127 }
120128
129+ OnStateChange ( OpenToClosedEventArgs ) ;
130+
121131 ConnectionState = ConnectionState . Closed ;
122132 }
123133 finally
@@ -140,7 +150,9 @@ public override string ConnectionString
140150 }
141151 }
142152
143- public override string Database => ConnectionStringBuilder . Database ;
153+ public override string Database => State == ConnectionState . Closed
154+ ? string . Empty
155+ : ConnectionStringBuilder . Database ;
144156
145157 public override ConnectionState State => ConnectionState ;
146158
@@ -152,7 +164,16 @@ public override string ConnectionString
152164 internal bool IsBusy => LastReader is { IsClosed : false } ;
153165
154166 public override string DataSource => string . Empty ; // TODO
155- public override string ServerVersion => string . Empty ; // TODO
167+
168+ public override string ServerVersion
169+ {
170+ get
171+ {
172+ EnsureConnectionOpen ( ) ;
173+
174+ return string . Empty ; // TODO ServerVersion
175+ }
176+ }
156177
157178 protected override YdbCommand CreateDbCommand ( )
158179 {
@@ -239,6 +260,11 @@ public override async ValueTask DisposeAsync()
239260 _disposed = true ;
240261 }
241262
263+ /// <summary>
264+ /// DB provider factory.
265+ /// </summary>
266+ protected override DbProviderFactory DbProviderFactory => YdbProviderFactory . Instance ;
267+
242268 /// <summary>
243269 /// Clears the connection pool. All idle physical connections in the pool of the given connection are
244270 /// immediately closed, and any busy connections which were opened before <see cref="ClearPool"/> was called
0 commit comments