66using System . Linq ;
77using System . Text ;
88using System . Text . RegularExpressions ;
9+ using System . Threading ;
910using System . Threading . Tasks ;
1011
1112namespace FreeSql . Duckdb
@@ -126,7 +127,7 @@ public void OnGet(Object<DbConnection> obj)
126127
127128#if net40
128129#else
129- async public Task OnGetAsync ( Object < DbConnection > obj )
130+ async public Task OnGetAsync ( Object < DbConnection > obj , CancellationToken cancellationToken )
130131 {
131132
132133 if ( _pool . IsAvailable )
@@ -135,7 +136,7 @@ async public Task OnGetAsync(Object<DbConnection> obj)
135136 throw new Exception ( CoreErrorStrings . S_ConnectionStringError_Check ( this . Name ) ) ;
136137
137138 if ( obj . Value . State != ConnectionState . Open )
138- await obj . Value . OpenAndAttachAsync ( Attaches ) ;
139+ await obj . Value . OpenAndAttachAsync ( Attaches , cancellationToken ) ;
139140 }
140141 }
141142#endif
@@ -206,26 +207,9 @@ public static void OpenAndAttach(this DbConnection that, string[] attach)
206207
207208#if net40
208209#else
209- async public static Task < bool > PingAsync ( this DbConnection that , bool isThrow = false )
210+ async public static Task OpenAndAttachAsync ( this DbConnection that , string [ ] attach , CancellationToken cancellationToken = default )
210211 {
211- try
212- {
213- using ( var cmd = PingCommand ( that ) )
214- {
215- await cmd . ExecuteNonQueryAsync ( ) ;
216- }
217- return true ;
218- }
219- catch
220- {
221- if ( that . State != ConnectionState . Closed ) try { that . Close ( ) ; } catch { }
222- if ( isThrow ) throw ;
223- return false ;
224- }
225- }
226- async public static Task OpenAndAttachAsync ( this DbConnection that , string [ ] attach )
227- {
228- await that . OpenAsync ( ) ;
212+ await that . OpenAsync ( cancellationToken ) ;
229213
230214 if ( attach ? . Any ( ) == true )
231215 {
@@ -235,7 +219,7 @@ async public static Task OpenAndAttachAsync(this DbConnection that, string[] att
235219
236220 var cmd = that . CreateCommand ( ) ;
237221 cmd . CommandText = sb . ToString ( ) ;
238- await cmd . ExecuteNonQueryAsync ( ) ;
222+ await cmd . ExecuteNonQueryAsync ( cancellationToken ) ;
239223 cmd . Dispose ( ) ;
240224 }
241225 }
0 commit comments