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 async Task CreateDatabaseAsync(int pageSize, bool forcedWrites, bool overwrite, CancellationToken cancellationToken = default) { var db = await ClientFactory.CreateDatabaseAsync(_options, cancellationToken).ConfigureAwait(false); var dpb = db.CreateDatabaseParameterBuffer(); dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 }); dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { _options.Dialect, 0, 0, 0 }); if (!string.IsNullOrEmpty(_options.UserID)) { dpb.Append(IscCodes.isc_dpb_user_name, _options.UserID); } if (_options.Charset.Length > 0) { var charset = Charset.GetCharset(_options.Charset); if (charset == null) { throw new ArgumentException("Character set is not valid."); } else { dpb.Append(IscCodes.isc_dpb_set_db_charset, charset.Name); } } dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0)); dpb.Append(IscCodes.isc_dpb_overwrite, (overwrite ? 1 : 0)); if (pageSize > 0) { dpb.Append(IscCodes.isc_dpb_page_size, pageSize); } try { if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password)) { await db.CreateDatabaseWithTrustedAuthAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false); } else { await db.CreateDatabaseAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false); } } finally { await db.DetachAsync(cancellationToken).ConfigureAwait(false); } }
public async Task DropDatabaseAsync(CancellationToken cancellationToken = default) { var db = await ClientFactory.CreateDatabaseAsync(_options, cancellationToken).ConfigureAwait(false); try { if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password)) { await db.AttachWithTrustedAuthAsync(BuildDpb(db, _options), _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false); } else { await db.AttachAsync(BuildDpb(db, _options), _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false); } await db.DropDatabaseAsync(cancellationToken).ConfigureAwait(false); } finally { await db.DetachAsync(cancellationToken).ConfigureAwait(false); } }