Exemple #1
0
    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);
        }
    }
Exemple #2
0
    public void CreateDatabase(int pageSize, bool forcedWrites, bool overwrite)
    {
        var db = ClientFactory.CreateDatabase(_options);

        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))
            {
                db.CreateDatabaseWithTrustedAuth(dpb, _options.Database, _options.CryptKey);
            }
            else
            {
                db.CreateDatabase(dpb, _options.Database, _options.CryptKey);
            }
        }
        finally
        {
            db.Detach();
        }
    }
Exemple #3
0
    public void DropDatabase()
    {
        var db = ClientFactory.CreateDatabase(_options);

        try
        {
            if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password))
            {
                db.AttachWithTrustedAuth(BuildDpb(db, _options), _options.Database, _options.CryptKey);
            }
            else
            {
                db.Attach(BuildDpb(db, _options), _options.Database, _options.CryptKey);
            }
            db.DropDatabase();
        }
        finally
        {
            db.Detach();
        }
    }