public void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            lock (this)
            {
                byte[] databaseBuffer = Encoding.Default.GetBytes(database);
                int    dbHandle       = Handle;

                // Clear status vector
                ClearStatusVector();

                _fbClient.isc_create_database(
                    _statusVector,
                    (short)databaseBuffer.Length,
                    databaseBuffer,
                    ref dbHandle,
                    (short)dpb.Length,
                    dpb.ToArray(),
                    0);

                ParseStatusVector(_statusVector);

                _handle = dbHandle;

                Detach();
            }
        }
        public void Attach(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            lock (this)
            {
                byte[] databaseBuffer = Encoding.Default.GetBytes(database);
                int    dbHandle       = 0;

                // Clear status vector
                ClearStatusVector();

                _fbClient.isc_attach_database(
                    _statusVector,
                    (short)databaseBuffer.Length,
                    databaseBuffer,
                    ref dbHandle,
                    (short)dpb.Length,
                    dpb.ToArray());

                ParseStatusVector(_statusVector);

                // Update the database handle
                _handle = dbHandle;

                // Get server version
                _serverVersion = GetServerVersion();
            }
        }
        private DatabaseParameterBuffer BuildDpb(IDatabase db, FbConnectionString options)
        {
            var dpb = new DatabaseParameterBuffer();

            dpb.Append(IscCodes.isc_dpb_version1);
            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 });
            dpb.Append(IscCodes.isc_dpb_lc_ctype, options.Charset);
            if (options.DbCachePages > 0)
            {
                dpb.Append(IscCodes.isc_dpb_num_buffers, options.DbCachePages);
            }
            if (!string.IsNullOrEmpty(options.UserID))
            {
                dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);
            }
            if (!string.IsNullOrEmpty(options.Role))
            {
                dpb.Append(IscCodes.isc_dpb_sql_role_name, options.Role);
            }
            dpb.Append(IscCodes.isc_dpb_connect_timeout, options.ConnectionTimeout);
            dpb.Append(IscCodes.isc_dpb_process_id, GetProcessId());
            dpb.Append(IscCodes.isc_dpb_process_name, GetProcessName());
            dpb.Append(IscCodes.isc_dpb_client_version, GetClientVersion());
            if (options.NoDatabaseTriggers)
            {
                dpb.Append(IscCodes.isc_dpb_no_db_triggers, 1);
            }
            if (options.NoGarbageCollect)
            {
                dpb.Append(IscCodes.isc_dpb_no_garbage_collect, (byte)0);
            }

            return(dpb);
        }
Exemplo n.º 4
0
        public virtual void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            lock (this.SyncObject)
            {
                try
                {
                    SendCreateToBuffer(dpb, database);
                    this.Flush();

                    try
                    {
                        ProcessCreateResponse(this.ReadGenericResponse());

                        this.Detach();
                    }
                    catch (IscException)
                    {
                        try
                        {
                            this.CloseConnection();
                        }
                        catch
                        {
                        }

                        throw;
                    }
                }
                catch (IOException)
                {
                    throw new IscException(IscCodes.isc_net_write_err);
                }
            }
        }
        public override void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database, byte[] cryptKey)
        {
            try
            {
                SendCreateToBuffer(dpb, database);
                XdrStream.Flush();

                try
                {
                    var response = ReadResponse();
                    response = ProcessCryptCallbackResponseIfNeeded(response, cryptKey);
                    ProcessCreateResponse(response as GenericResponse);

                    Detach();
                }
                catch (IscException)
                {
                    try
                    {
                        CloseConnection();
                    }
                    catch
                    { }
                    throw;
                }
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_net_write_err, ex);
            }
        }
 public void CreateDatabase(DatabaseParameterBuffer dpb)
 {
     using (var db = ClientFactory.CreateDatabase(_options))
     {
         db.CreateDatabase(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey);
     }
 }
Exemplo n.º 7
0
        public virtual void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            lock (SyncObject)
            {
                try
                {
                    SendCreateToBuffer(dpb, database);
                    XdrStream.Flush();

                    try
                    {
                        ProcessCreateResponse(ReadGenericResponse());

                        Detach();
                    }
                    catch (IscException)
                    {
                        try
                        {
                            CloseConnection();
                        }
                        catch
                        { }
                        throw;
                    }
                }
                catch (IOException ex)
                {
                    throw IscException.ForErrorCode(IscCodes.isc_net_write_err, ex);
                }
            }
        }
Exemplo n.º 8
0
        public virtual void Attach(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            lock (this.SyncObject)
            {
                try
                {
                    SendAttachToBuffer(dpb, database);
                    this.Flush();
                    ProcessAttachResponse(this.ReadGenericResponse());
                }
                catch (IOException)
                {
                    try
                    {
                        this.Detach();
                    }
                    catch (Exception)
                    {
                    }

                    throw new IscException(IscCodes.isc_net_write_err);
                }

                // Get server version
                this.serverVersion = this.GetServerVersion();
            }
        }
Exemplo n.º 9
0
        public override void AttachWithTrustedAuth(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            lock (SyncObject)
            {
                try
                {
                    using (SspiHelper sspiHelper = new SspiHelper())
                    {
                        byte[] authData = sspiHelper.InitializeClientSecurity();
                        SendTrustedAuthToBuffer(dpb, authData);
                        SendAttachToBuffer(dpb, database);
                        XdrStream.Flush();

                        IResponse response = ReadResponse();
                        ProcessTrustedAuthResponse(sspiHelper, ref response);
                        ProcessAttachResponse((GenericResponse)response);
                    }
                }
                catch (IscException)
                {
                    SafelyDetach();
                    throw;
                }
                catch (IOException ex)
                {
                    SafelyDetach();
                    throw IscException.ForErrorCode(IscCodes.isc_net_write_err, ex);
                }

                AfterAttachActions();
            }
        }
Exemplo n.º 10
0
        public void Connect()
        {
            if (Charset.GetCharset(_options.Charset) == null)
            {
                throw new FbException("Invalid character set specified");
            }

            try
            {
                _db            = ClientFactory.CreateDatabase(_options);
                _db.Charset    = Charset.GetCharset(_options.Charset);
                _db.Dialect    = _options.Dialect;
                _db.PacketSize = _options.PacketSize;

                DatabaseParameterBuffer dpb = BuildDpb(_db, _options);

                if (_options.FallIntoTrustedAuth)
                {
                    _db.AttachWithTrustedAuth(dpb, _options.DataSource, _options.Port, _options.Database);
                }
                else
                {
                    _db.Attach(dpb, _options.DataSource, _options.Port, _options.Database);
                }
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
 protected virtual void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     Write(IscCodes.op_create);
     Write(0);
     WriteBuffer(Encoding.Default.GetBytes(database));
     WriteBuffer(dpb.ToArray());
 }
Exemplo n.º 12
0
        public override void Attach(DatabaseParameterBuffer dpb, string dataSource, int port, string database, byte[] cryptKey)
        {
            try
            {
                SendAttachToBuffer(dpb, database);
                XdrStream.Flush();
                var response = ReadResponse();
                while (response is CryptKeyCallbackReponse cryptResponse)
                {
                    XdrStream.Write(IscCodes.op_crypt_key_callback);
                    XdrStream.WriteBuffer(cryptKey);
                    XdrStream.Flush();
                    response = ReadResponse();
                }
                ProcessAttachResponse(response as GenericResponse);
            }
            catch (IscException)
            {
                SafelyDetach();
                throw;
            }
            catch (IOException ex)
            {
                SafelyDetach();
                throw IscException.ForErrorCode(IscCodes.isc_net_write_err, ex);
            }

            AfterAttachActions();
        }
 protected virtual void SendAttachToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     // Attach to the database
     Write(IscCodes.op_attach);
     Write(0);                                                       // Database object ID
     WriteBuffer(Encoding.Default.GetBytes(database));               // Database PATH
     WriteBuffer(dpb.ToArray());                                     // DPB Parameter buffer
 }
Exemplo n.º 14
0
 protected override void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     this.Write(IscCodes.op_create);
     this.Write(0);
     dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
     this.WriteBuffer(Encoding.UTF8.GetBytes(database));
     this.WriteBuffer(dpb.ToArray());
 }
Exemplo n.º 15
0
 protected override void SendAttachToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     // Attach to the database
     this.Write(IscCodes.op_attach);
     this.Write(0);                                      // Database	object ID
     dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
     this.WriteBuffer(Encoding.UTF8.GetBytes(database)); // Database	PATH
     this.WriteBuffer(dpb.ToArray());                    // DPB Parameter buffer
 }
Exemplo n.º 16
0
 protected virtual void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     Xdr.Write(IscCodes.op_create);
     Xdr.Write(DatabaseObjectId);
     if (!string.IsNullOrEmpty(Password))
     {
         dpb.Append(IscCodes.isc_dpb_password, Password);
     }
     Xdr.WriteBuffer(Encoding.Default.GetBytes(database));
     Xdr.WriteBuffer(dpb.ToArray());
 }
Exemplo n.º 17
0
 protected virtual void SendAttachToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     XdrStream.Write(IscCodes.op_attach);
     XdrStream.Write(0);
     if (!string.IsNullOrEmpty(Password))
     {
         dpb.Append(IscCodes.isc_dpb_password, Password);
     }
     XdrStream.WriteBuffer(Encoding2.Default.GetBytes(database));
     XdrStream.WriteBuffer(dpb.ToArray());
 }
 protected override void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     Xdr.Write(IscCodes.op_create);
     Xdr.Write(0);
     if (!string.IsNullOrEmpty(Password))
     {
         dpb.Append(IscCodes.isc_dpb_password, Password);
     }
     dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
     Xdr.WriteBuffer(Encoding.UTF8.GetBytes(database));
     Xdr.WriteBuffer(dpb.ToArray());
 }
        protected virtual void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
        {
            XdrStream.Write(IscCodes.op_create);
#warning Some constant for default database object ID
            XdrStream.Write(0);
            if (!string.IsNullOrEmpty(Password))
            {
                dpb.Append(IscCodes.isc_dpb_password, Password);
            }
            XdrStream.WriteBuffer(Encoding.UTF8.GetBytes(database));
            XdrStream.WriteBuffer(dpb.ToArray());
        }
Exemplo n.º 20
0
 protected override void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     XdrStream.Write(IscCodes.op_create);
     XdrStream.Write(0);
     if (AuthData != null)
     {
         dpb.Append(IscCodes.isc_dpb_specific_auth_data, AuthData);
     }
     dpb.Append(IscCodes.isc_dpb_utf8_filename, 0);
     XdrStream.WriteBuffer(Encoding.UTF8.GetBytes(database));
     XdrStream.WriteBuffer(dpb.ToArray());
 }
Exemplo n.º 21
0
 public virtual void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database, byte[] cryptKey)
 {
     try
     {
         SendCreateToBuffer(dpb, database);
         Xdr.Flush();
         ProcessCreateResponse(ReadResponse <GenericResponse>());
     }
     catch (IOException ex)
     {
         throw IscException.ForErrorCode(IscCodes.isc_network_error, ex);
     }
 }
Exemplo n.º 22
0
        public override void CreateDatabaseWithTrustedAuth(DatabaseParameterBuffer dpb, string dataSource, int port, string database, byte[] cryptKey)
        {
            using (var sspiHelper = new SspiHelper())
            {
                var authData = sspiHelper.InitializeClientSecurity();
                SendTrustedAuthToBuffer(dpb, authData);
                SendCreateToBuffer(dpb, database);
                Xdr.Flush();

                var response = ReadResponse();
                ProcessTrustedAuthResponse(sspiHelper, ref response);
                ProcessCreateResponse((GenericResponse)response);
            }
        }
Exemplo n.º 23
0
 public void CreateDatabase(DatabaseParameterBuffer dpb)
 {
     using (var db = ClientFactory.CreateDatabase(_options))
     {
         if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password))
         {
             db.CreateDatabaseWithTrustedAuth(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey);
         }
         else
         {
             db.CreateDatabase(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey);
         }
     }
 }
Exemplo n.º 24
0
        public void Attach(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            int dbHandle = 0;

            // Clear status vector
            this.ClearStatusVector();

            lock (this)
            {
                SafeNativeMethods.isc_get_current_database(this.statusVector, ref dbHandle);

                this.handle = dbHandle;
            }
        }
Exemplo n.º 25
0
        private static void CreateDatabaseImpl(string connectionString, int pageSize = 4096, bool forcedWrites = true, bool overwrite = false)
        {
            FbConnectionString options = new FbConnectionString(connectionString);

            options.Validate();

            try
            {
                DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

                dpb.Append(IscCodes.isc_dpb_version1);
                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)
                {
                    Charset 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);
                }

                using (FbConnectionInternal db = new FbConnectionInternal(options))
                {
                    db.CreateDatabase(dpb);
                }
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Exemplo n.º 26
0
        public void Attach(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            byte[] databaseBuffer = Encoding.UTF8.GetBytes(database);

            ClearStatusVector();

            _fbClient.isc_attach_database(
                _statusVector,
                (short)databaseBuffer.Length,
                databaseBuffer,
                ref _handle,
                dpb.Length,
                dpb.ToArray());

            ProcessStatusVector(_statusVector);

            _serverVersion = GetServerVersion();
        }
Exemplo n.º 27
0
        public void Connect()
        {
            try
            {
                this.db            = ClientFactory.CreateDatabase(this.options.ServerType);
                this.db.Charset    = Charset.SupportedCharsets[this.options.Charset];
                this.db.Dialect    = this.options.Dialect;
                this.db.PacketSize = this.options.PacketSize;

                DatabaseParameterBuffer dpb = this.BuildDpb(this.db, options);

                this.db.Attach(dpb, this.options.DataSource, this.options.Port, this.options.Database);
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Exemplo n.º 28
0
        public void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            byte[] databaseBuffer = Encoding.UTF8.GetBytes(database);

            ClearStatusVector();

            _fbClient.isc_create_database(
                _statusVector,
                (short)databaseBuffer.Length,
                databaseBuffer,
                ref _handle,
                dpb.Length,
                dpb.ToArray(),
                0);

            ProcessStatusVector(_statusVector);

            Detach();
        }
        public void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database, byte[] cryptKey)
        {
            CheckCryptKeyForSupport(cryptKey);

            var databaseBuffer = Encoding2.Default.GetBytes(database);

            ClearStatusVector();

            _fbClient.isc_create_database(
                _statusVector,
                (short)databaseBuffer.Length,
                databaseBuffer,
                ref _handle,
                dpb.Length,
                dpb.ToArray(),
                0);

            ProcessStatusVector(_statusVector);
        }
Exemplo n.º 30
0
        public void Attach(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            lock (this)
            {
                try
                {
                    this.connection.Connect(dataSource, port, this.packetSize, this.charset);

                    this.Identify(database);

                    this.Send.Write(IscCodes.op_attach);
                    this.Send.Write((int)0);                                    // Database	object ID
                    this.Send.Write(database);                                  // Database	PATH
                    this.Send.WriteBuffer(dpb.ToArray());                       // DPB Parameter buffer
                    this.Send.Flush();

                    try
                    {
                        this.handle = this.ReadGenericResponse().ObjectHandle;
                    }
                    catch (IscException)
                    {
                        try
                        {
                            this.connection.Disconnect();
                        }
                        catch
                        {
                        }
                        throw;
                    }
                }
                catch (IOException)
                {
                    this.connection.Disconnect();

                    throw new IscException(IscCodes.isc_net_write_err);
                }

                // Get server version
                this.serverVersion = this.GetServerVersion();
            }
        }