public async Task <DataTable> GetSchema(FbConnection connection, string collectionName, string[] restrictions, AsyncWrappingCommonArgs async) { var dataTable = new DataTable(collectionName); var command = BuildCommand(connection, collectionName, ParseRestrictions(restrictions)); try { using (var adapter = new FbDataAdapter(command)) { try { adapter.Fill(dataTable); } catch (Exception ex) { throw FbException.Create(ex); } } } finally { #if NET48 || NETSTANDARD2_0 command.Dispose(); await Task.CompletedTask.ConfigureAwait(false); #else await async.AsyncSyncCallNoCancellation(command.DisposeAsync, command.Dispose).ConfigureAwait(false); #endif } TrimStringFields(dataTable); ProcessResult(dataTable); return(dataTable); }
public void Start(string sessionName) { var version = _version; if (version == FbTraceVersion.Detect) { version = DetectVersion(); } try { var config = string.Join(Environment.NewLine, DatabasesConfigurations.BuildConfiguration(version), ServiceConfiguration?.BuildConfiguration(version) ?? string.Empty); Open(); var startSpb = new ServiceParameterBuffer2(); startSpb.Append(IscCodes.isc_action_svc_trace_start); if (!string.IsNullOrEmpty(sessionName)) { startSpb.Append2(IscCodes.isc_spb_trc_name, sessionName); } startSpb.Append2(IscCodes.isc_spb_trc_cfg, config); StartTask(startSpb); ProcessServiceOutput(ServiceParameterBufferBase.Empty); } catch (Exception ex) { throw FbException.Create(ex); } finally { Close(); } }
public async Task StartAsync(string sessionName, CancellationToken cancellationToken = default) { var version = _version; if (version == FbTraceVersion.Detect) { version = await DetectVersionAsync(cancellationToken).ConfigureAwait(false); } try { var config = string.Join(Environment.NewLine, DatabasesConfigurations.BuildConfiguration(version), ServiceConfiguration?.BuildConfiguration(version) ?? string.Empty); await OpenAsync(cancellationToken).ConfigureAwait(false); var startSpb = new ServiceParameterBuffer2(); startSpb.Append(IscCodes.isc_action_svc_trace_start); if (!string.IsNullOrEmpty(sessionName)) { startSpb.Append2(IscCodes.isc_spb_trc_name, sessionName); } startSpb.Append2(IscCodes.isc_spb_trc_cfg, config); await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false); await ProcessServiceOutputAsync(ServiceParameterBufferBase.Empty, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { throw FbException.Create(ex); } finally { await CloseAsync(cancellationToken).ConfigureAwait(false); } }
public DataTable GetSchema(FbConnection connection, string collectionName, string[] restrictions) { var dataTable = new DataTable(collectionName); var command = BuildCommand(connection, collectionName, ParseRestrictions(restrictions)); try { using (var adapter = new FbDataAdapter(command)) { try { adapter.Fill(dataTable); } catch (Exception ex) { throw FbException.Create(ex); } } } finally { #if NET48 || NETSTANDARD2_0 command.Dispose(); #else command.Dispose(); #endif } TrimStringFields(dataTable); ProcessResult(dataTable); return(dataTable); }
private async Task ExecuteImpl(AsyncWrappingCommonArgs async) { EnsureDatabase(); try { await Open(async).ConfigureAwait(false); var startSpb = new ServiceParameterBuffer(); startSpb.Append(IscCodes.isc_action_svc_nbak); startSpb.Append(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding); startSpb.Append(IscCodes.isc_spb_nbk_level, _level); startSpb.Append(IscCodes.isc_spb_nbk_file, BackupFile, SpbFilenameEncoding); startSpb.Append(IscCodes.isc_spb_nbk_direct, DirectIO ? "ON" : "OFF"); startSpb.Append(IscCodes.isc_spb_options, (int)Options); await StartTask(startSpb, async).ConfigureAwait(false); await ProcessServiceOutput(EmptySpb, async).ConfigureAwait(false); } catch (Exception ex) { throw FbException.Create(ex); } finally { await Close(async).ConfigureAwait(false); } }
private async Task StartImpl(string sessionName, AsyncWrappingCommonArgs async) { var version = _version; if (version == FbTraceVersion.Detect) { version = DetectVersion(); } try { var config = string.Join(Environment.NewLine, DatabasesConfigurations.BuildConfiguration(version), ServiceConfiguration?.BuildConfiguration(version) ?? string.Empty); await Open(async).ConfigureAwait(false); var startSpb = new ServiceParameterBuffer(); startSpb.Append(IscCodes.isc_action_svc_trace_start); if (!string.IsNullOrEmpty(sessionName)) { startSpb.Append(IscCodes.isc_spb_trc_name, sessionName); } startSpb.Append(IscCodes.isc_spb_trc_cfg, config); await StartTask(startSpb, async).ConfigureAwait(false); await ProcessServiceOutput(EmptySpb, async).ConfigureAwait(false); } catch (Exception ex) { throw FbException.Create(ex); } finally { await Close(async).ConfigureAwait(false); } }
public async Task ExecuteAsync(CancellationToken cancellationToken = default) { EnsureDatabase(); try { await OpenAsync(cancellationToken).ConfigureAwait(false); var startSpb = new ServiceParameterBuffer2(); startSpb.Append(IscCodes.isc_action_svc_backup); startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding); startSpb.Append2(IscCodes.isc_spb_bkp_file, "stdout", SpbFilenameEncoding); if (!string.IsNullOrEmpty(SkipData)) { startSpb.Append2(IscCodes.isc_spb_bkp_skip_data, SkipData); } startSpb.Append(IscCodes.isc_spb_options, (int)Options); await StartTaskAsync(startSpb, cancellationToken).ConfigureAwait(false); await ReadOutputAsync(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { throw FbException.Create(ex); } finally { await CloseAsync(cancellationToken).ConfigureAwait(false); } }
private async Task ExecuteImpl(AsyncWrappingCommonArgs async) { EnsureDatabase(); try { await Open(async).ConfigureAwait(false); var startSpb = new ServiceParameterBuffer(); startSpb.Append(IscCodes.isc_action_svc_backup); startSpb.Append(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding); startSpb.Append(IscCodes.isc_spb_bkp_file, "stdout", SpbFilenameEncoding); if (!string.IsNullOrEmpty(SkipData)) { startSpb.Append(IscCodes.isc_spb_bkp_skip_data, SkipData); } startSpb.Append(IscCodes.isc_spb_options, (int)Options); await StartTask(startSpb, async).ConfigureAwait(false); await ReadOutput(async).ConfigureAwait(false); } catch (Exception ex) { throw FbException.Create(ex); } finally { await Close(async).ConfigureAwait(false); } }
public void Execute() { EnsureDatabase(); try { Open(); var startSpb = new ServiceParameterBuffer2(); startSpb.Append(IscCodes.isc_action_svc_backup); startSpb.Append2(IscCodes.isc_spb_dbname, Database, SpbFilenameEncoding); startSpb.Append2(IscCodes.isc_spb_bkp_file, "stdout", SpbFilenameEncoding); if (!string.IsNullOrEmpty(SkipData)) { startSpb.Append2(IscCodes.isc_spb_bkp_skip_data, SkipData); } startSpb.Append(IscCodes.isc_spb_options, (int)Options); StartTask(startSpb); ReadOutput(); } catch (Exception ex) { throw FbException.Create(ex); } finally { Close(); } }
public override async Task ChangeDatabaseAsync(string db, CancellationToken cancellationToken = default) #endif { CheckClosed(); if (string.IsNullOrEmpty(db)) { throw new InvalidOperationException("Database name is not valid."); } var oldConnectionString = _connectionString; try { var csb = new FbConnectionStringBuilder(_connectionString); /* Close current connection */ await CloseAsync().ConfigureAwait(false); /* Set up the new Database */ csb.Database = db; ConnectionString = csb.ToString(); /* Open new connection */ await OpenAsync(cancellationToken).ConfigureAwait(false); } catch (IscException ex) { ConnectionString = oldConnectionString; throw FbException.Create(ex); } }
public override void ChangeDatabase(string db) { CheckClosed(); if (string.IsNullOrEmpty(db)) { throw new InvalidOperationException("Database name is not valid."); } var oldConnectionString = _connectionString; try { var csb = new FbConnectionStringBuilder(_connectionString); /* Close current connection */ Close(); /* Set up the new Database */ csb.Database = db; ConnectionString = csb.ToString(); /* Open new connection */ Open(); } catch (IscException ex) { ConnectionString = oldConnectionString; throw FbException.Create(ex); } }
public async Task ConnectAsync(CancellationToken cancellationToken = default) { if (Charset.GetCharset(_options.Charset) == null) { throw FbException.Create("Invalid character set specified"); } try { _db = await ClientFactory.CreateDatabaseAsync(_options, cancellationToken).ConfigureAwait(false); _db.Charset = Charset.GetCharset(_options.Charset); _db.Dialect = _options.Dialect; _db.PacketSize = _options.PacketSize; var dpb = BuildDpb(_db, _options); if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password)) { await _db.AttachWithTrustedAuthAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false); } else { await _db.AttachAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false); } } catch (IscException ex) { throw FbException.Create(ex); } }
public void Connect() { if (Charset.GetCharset(_options.Charset) == null) { throw FbException.Create("Invalid character set specified"); } try { _db = ClientFactory.CreateDatabase(_options); _db.Charset = Charset.GetCharset(_options.Charset); _db.Dialect = _options.Dialect; _db.PacketSize = _options.PacketSize; var dpb = BuildDpb(_db, _options); if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password)) { _db.AttachWithTrustedAuth(dpb, _options.Database, _options.CryptKey); } else { _db.Attach(dpb, _options.Database, _options.CryptKey); } } catch (IscException ex) { throw FbException.Create(ex); } }
/// <summary> /// Check specific connection provider if connection broken /// </summary> /// <param name="ex">Exception from Exec void</param> /// <returns>true - connection broken</returns> protected override bool CheckConnectionBroken(Exception ex) { bool b = false; FbException e = ex as FbException; //if (e != null && e.Errors != null && e.Errors.Count > 0) // b = e.Errors[0].Number == 335544726; // Error no connect DB return(b); }