Exemple #1
0
        protected override void Dispose(bool disposing)
        {
            lock (this)
            {
                if (!_disposed)
                {
                    try
                    {
                        // release any unmanaged resources
                        Close();

                        if (disposing)
                        {
                            // release any managed resources
                            _innerConnection  = null;
                            _options          = null;
                            _connectionString = null;
                        }
                    }
                    catch
                    { }
                    finally
                    {
                        _disposed = true;
                        base.Dispose(disposing);
                    }
                }
            }
        }
        public FbConnectionPool(string connectionString)
        {
            this.connectionString = connectionString;
            this.options          = new FbConnectionString(connectionString);
            this.lifeTime         = this.options.ConnectionLifeTime * TimeSpan.TicksPerSecond;

            if (this.options.MaxPoolSize == 0)
            {
                this.locked   = ArrayList.Synchronized(new ArrayList());
                this.unlocked = ArrayList.Synchronized(new ArrayList());
            }
            else
            {
                this.locked   = ArrayList.Synchronized(new ArrayList(this.options.MaxPoolSize));
                this.unlocked = ArrayList.Synchronized(new ArrayList(this.options.MaxPoolSize));
            }

            // If a	minimun	number of connections is requested initialize the pool
            this.Initialize();

            // Start the cleanup only if needed
            if (this.lifeTime != 0)
            {
                long interval = Convert.ToInt64(TimeSpan.FromTicks(this.lifeTime).TotalMilliseconds);
                this.cleanupTimer = new Timer(new TimerCallback(this.CleanupWorker), this, interval, interval);
            }
        }
Exemple #3
0
        public FbConnectionInternal(FbConnectionString options)
        {
            _preparedCommands = new List <WeakReference>();
            _preparedCommandsCleanupSyncRoot = new object();

            _options = options;
        }
        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);
        }
Exemple #5
0
        protected override void Dispose(bool disposing)
        {
            lock (this)
            {
                if (!this.disposed)
                {
                    try
                    {
                        // release any unmanaged resources
                        this.Close();

                        if (disposing)
                        {
                            // release any managed resources
                            this.innerConnection  = null;
                            this.options          = null;
                            this.connectionString = null;
                        }

                        this.disposed = true;
                    }
                    catch
                    {
                    }
                    finally
                    {
                        base.Dispose(disposing);
                    }
                }
            }
        }
Exemple #6
0
            static FbConnectionInternal CreateNewConnection(FbConnectionString connectionString)
            {
                var result = new FbConnectionInternal(connectionString);

                result.Connect();
                return(result);
            }
        private static IDatabase CreateManagedDatabase(FbConnectionString options)
        {
            var connection = new GdsConnection(options.UserID, options.Password, options.DataSource, options.Port, options.PacketSize, Charset.GetCharset(options.Charset));

            connection.Connect();
            connection.Identify(options.Database);

            switch (connection.ProtocolVersion)
            {
            case IscCodes.PROTOCOL_VERSION13:
                return(new Client.Managed.Version13.GdsDatabase(connection));

            case IscCodes.PROTOCOL_VERSION12:
                return(new Client.Managed.Version12.GdsDatabase(connection));

            case IscCodes.PROTOCOL_VERSION11:
                return(new Client.Managed.Version11.GdsDatabase(connection));

            case IscCodes.PROTOCOL_VERSION10:
                return(new Client.Managed.Version10.GdsDatabase(connection));

            default:
                throw UnsupportedProtocolException();
            }
        }
Exemple #8
0
 public Pool(FbConnectionString connectionString)
 {
     _syncRoot         = new object();
     _connectionString = connectionString;
     _available        = new Stack <Item>();
     _busy             = new List <FbConnectionInternal>();
 }
 public Pool(FbConnectionString connectionString)
 {
     _disposed         = false;
     _syncRoot         = new object();
     _connectionString = connectionString;
     _available        = new Queue <Item>();
     _busy             = new List <FbConnectionInternal>();
 }
			public Pool(FbConnectionString connectionString)
			{
				_disposed = false;
				_syncRoot = new object();
				_connectionString = connectionString;
				_available = new Queue<Item>();
				_busy = new List<FbConnectionInternal>();
			}
Exemple #11
0
 FbConnectionInternal CreateNewConnectionIfPossibleImpl(FbConnectionString connectionString)
 {
     if (_busy.Count() + 1 > connectionString.MaxPoolSize)
     {
         throw new InvalidOperationException("Connection pool is full.");
     }
     return(CreateNewConnection(connectionString));
 }
Exemple #12
0
            static FbConnectionInternal CreateNewConnection(FbConnectionString connectionString, FbConnection owner)
            {
                var result = new FbConnectionInternal(connectionString);

                result.SetOwningConnection(owner);
                result.Connect();
                return(result);
            }
        public FbConnectionInternal(FbConnectionString options)
        {
            this.preparedCommands = new List<WeakReference>();
            this.preparedCommandsCleanupSyncRoot = new object();

            this.options = options;

            GC.SuppressFinalize(this);
        }
Exemple #14
0
        public FbConnectionInternal(FbConnectionString options)
        {
            this.preparedCommands = new List <WeakReference>();
            this.preparedCommandsCleanupSyncRoot = new object();

            this.options = options;

            GC.SuppressFinalize(this);
        }
		public void ParsingNormalConnectionStringTest()
		{
			const string ConnectionString = "datasource=testserver;database=testdb.fdb;user=testuser;password=testpwd";
			var cs = new FbConnectionString(ConnectionString);
			Assert.AreEqual("testserver", cs.DataSource);
			Assert.AreEqual("testdb.fdb", cs.Database);
			Assert.AreEqual("testuser", cs.UserID);
			Assert.AreEqual("testpwd", cs.Password);
		}
Exemple #16
0
        internal void ClearPool(FbConnectionString connectionString)
        {
            CheckDisposed();

            if (_pools.TryGetValue(connectionString.NormalizedConnectionString, out var pool))
            {
                pool.ClearPool();
            }
        }
        public void NormalizedConnectionStringIgnoresCultureTest()
        {
            const string ConnectionString = "datasource=testserver;database=testdb.fdb;user=testuser;password=testpwd";
            var cs = new FbConnectionString(ConnectionString);
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
            var s1 = cs.NormalizedConnectionString;
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("cs-CZ");
            var s2 = cs.NormalizedConnectionString;

            Assert.AreEqual(s1, s2);
        }
Exemple #18
0
        public FbConnection(string connectionString)
            : base()
        {
            this.options          = new FbConnectionString();
            this.state            = ConnectionState.Closed;
            this.connectionString = string.Empty;

            if (!string.IsNullOrEmpty(connectionString))
            {
                this.ConnectionString = connectionString;
            }
        }
Exemple #19
0
        public FbConnection(string connectionString)
            : base()
        {
            this.options = new FbConnectionString();
            this.state = ConnectionState.Closed;
            this.connectionString = string.Empty;

            if (!string.IsNullOrEmpty(connectionString))
            {
                this.ConnectionString = connectionString;
            }
        }
Exemple #20
0
        public FbConnection(string connectionString)
            : base()
        {
            _options          = new FbConnectionString();
            _state            = ConnectionState.Closed;
            _connectionString = string.Empty;

            if (!string.IsNullOrEmpty(connectionString))
            {
                ConnectionString = connectionString;
            }
        }
 public void DNET()
 {
     const string ConnectionString = @"data source=localhost;port number=20455;initial catalog=;user id=SYSDBA;password=masterkey;pooling=False;packet size=16384;character set=UTF8";
     var cs = new FbConnectionString(ConnectionString);
     Assert.AreEqual("localhost", cs.DataSource);
     Assert.AreEqual(20455, cs.Port);
     Assert.AreEqual(string.Empty, cs.Database);
     Assert.AreEqual("SYSDBA", cs.UserID);
     Assert.AreEqual("masterkey", cs.Password);
     Assert.AreEqual(false, cs.Pooling);
     Assert.AreEqual(16384, cs.PacketSize);
     Assert.AreEqual("UTF8", cs.Charset);
 }
        public static IServiceManager CreateServiceManager(FbConnectionString options)
        {
            switch (options.ServerType)
            {
            case FbServerType.Default:
                return(CreateManagedServiceManager(options));

            case FbServerType.Embedded:
                return(new Client.Native.FesServiceManager(options.ClientLibrary, Charset.GetCharset(options.Charset)));

            default:
                throw IncorrectServerTypeException();
            }
        }
Exemple #23
0
		public static IServiceManager CreateServiceManager(FbConnectionString options)
		{
			switch (options.ServerType)
			{
				case FbServerType.Default:
					return CreateManagedServiceManager(options);

				case FbServerType.Embedded:
					// PInvoke Client
					return new FirebirdSql.Data.Client.Native.FesServiceManager(options.ClientLibrary, Charset.GetCharset(options.Charset));

				default:
					throw new NotSupportedException("Specified server type is not correct.");
			}
		}
Exemple #24
0
        public static IServiceManager CreateServiceManager(FbConnectionString options)
        {
            switch (options.ServerType)
            {
            case FbServerType.Default:
                return(CreateManagedServiceManager(options));

            case FbServerType.Embedded:
                // PInvoke Client
                return(new FirebirdSql.Data.Client.Native.FesServiceManager(options.ClientLibrary, Charset.GetCharset(options.Charset)));

            default:
                throw new NotSupportedException("Specified server type is not correct.");
            }
        }
Exemple #25
0
 public void Dispose()
 {
     lock (_syncRoot)
     {
         if (_disposed)
         {
             return;
         }
         _disposed         = true;
         _connectionString = null;
         CleanConnectionsImpl();
         _available = null;
         _busy      = null;
     }
 }
Exemple #26
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (!_disposed)
         {
             _disposed = true;
             Close();
             _innerConnection  = null;
             _options          = null;
             _connectionString = null;
             base.Dispose(disposing);
         }
     }
 }
Exemple #27
0
        public static void DropDatabase(string connectionString)
        {
            FbConnectionString options = new FbConnectionString(connectionString);

            options.Validate();

            try
            {
                FbConnectionInternal db = new FbConnectionInternal(options);
                db.DropDatabase();
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Exemple #28
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);
            }
        }
 public void ParsingMultilineConnectionStringTest()
 {
     const string ConnectionString = @"DataSource=S05-04;
      User= SYSDBA;
      Password= masterkey;
      Role= ;
      Database=Termine;
      Port=3050;
      Dialect=3;
      Charset=ISO8859_1;
      Connection lifetime=0;
      Connection timeout=15;
      Pooling=True;
      Packet Size=8192;";
     var cs = new FbConnectionString(ConnectionString);
     Assert.AreEqual("Termine", cs.Database);
     Assert.AreEqual("", cs.Role);
 }
        private static IServiceManager CreateManagedServiceManager(FbConnectionString options)
        {
            FirebirdSql.Data.Client.Managed.Version10.GdsConnection connection = new FirebirdSql.Data.Client.Managed.Version10.GdsConnection(options.DataSource, options.Port, options.PacketSize, Charset.GetCharset(options.Charset));

            connection.Connect();
            connection.Identify(!string.IsNullOrEmpty(options.Database) ? options.Database : string.Empty);

            switch (connection.ProtocolVersion)
            {
            case IscCodes.PROTOCOL_VERSION12:
            case IscCodes.PROTOCOL_VERSION11:
            case IscCodes.PROTOCOL_VERSION10:
                return(new FirebirdSql.Data.Client.Managed.Version10.GdsServiceManager(connection));

            default:
                throw new NotSupportedException("Protocol not supported.");
            }
        }
 public void Disconnect()
 {
     if (_db != null)
     {
         try
         {
             _db.Dispose();
         }
         catch
         { }
         finally
         {
             _db = null;
             _owningConnection = null;
             _options          = null;
         }
     }
 }
        private static IDatabase CreateManagedDatabase(FbConnectionString options)
        {
            FirebirdSql.Data.Client.Managed.Version10.GdsConnection connection = new FirebirdSql.Data.Client.Managed.Version10.GdsConnection(options.DataSource, options.Port, options.PacketSize, Charset.GetCharset(options.Charset));

            connection.Connect();
            connection.Identify(options.Database);

            switch (connection.ProtocolVersion)
            {
				case IscCodes.PROTOCOL_VERSION12:
					return new FirebirdSql.Data.Client.Managed.Version12.GdsDatabase(connection);
                case IscCodes.PROTOCOL_VERSION11:
                    return new FirebirdSql.Data.Client.Managed.Version11.GdsDatabase(connection);
                case IscCodes.PROTOCOL_VERSION10:
                    return new FirebirdSql.Data.Client.Managed.Version10.GdsDatabase(connection);
                default:
                    throw new NotSupportedException("Protocol not supported.");
            }
        }
Exemple #33
0
 public void Disconnect()
 {
     if (this.db != null)
     {
         try
         {
             this.db.Dispose();
         }
         catch
         {
         }
         finally
         {
             this.db = null;
             this.owningConnection = null;
             this.options          = null;
         }
     }
 }
        private static IServiceManager CreateManagedServiceManager(FbConnectionString options)
        {
            var connection = new GdsConnection(options.UserID, options.Password, options.DataSource, options.Port, options.PacketSize, Charset.GetCharset(options.Charset), options.Compression);

            connection.Connect();
            connection.Identify(!string.IsNullOrEmpty(options.Database) ? options.Database : string.Empty);

            switch (connection.ProtocolVersion)
            {
            case IscCodes.PROTOCOL_VERSION13:
            case IscCodes.PROTOCOL_VERSION12:
            case IscCodes.PROTOCOL_VERSION11:
            case IscCodes.PROTOCOL_VERSION10:
                return(new Client.Managed.Version10.GdsServiceManager(connection));

            default:
                throw UnsupportedProtocolException();
            }
        }
Exemple #35
0
		public static IDatabase CreateDatabase(FbConnectionString options)
		{
			switch (options.ServerType)
			{
				case FbServerType.Default:
					// Managed Client
					return CreateManagedDatabase(options);

				case FbServerType.Embedded:
					// Native (PInvoke) Client
					return new FirebirdSql.Data.Client.Native.FesDatabase(options.ClientLibrary, Charset.GetCharset(options.Charset));

				case FbServerType.Context:
					// External Engine (PInvoke) Client
					return new FirebirdSql.Data.Client.ExternalEngine.ExtDatabase();

				default:
					throw new NotSupportedException("Specified server type is not correct.");
			}
		}
Exemple #36
0
        public static IDatabase CreateDatabase(FbConnectionString options)
        {
            switch (options.ServerType)
            {
            case FbServerType.Default:
                // Managed Client
                return(CreateManagedDatabase(options));

            case FbServerType.Embedded:
                // Native (PInvoke) Client
                return(new FirebirdSql.Data.Client.Native.FesDatabase(options.ClientLibrary, Charset.GetCharset(options.Charset)));

            case FbServerType.Context:
                // External Engine (PInvoke) Client
                return(new FirebirdSql.Data.Client.ExternalEngine.ExtDatabase());

            default:
                throw new NotSupportedException("Specified server type is not correct.");
            }
        }
        private static IDatabase CreateManagedDatabase(FbConnectionString options)
        {
            FirebirdSql.Data.Client.Managed.Version10.GdsConnection connection = new FirebirdSql.Data.Client.Managed.Version10.GdsConnection(options.DataSource, options.Port, options.PacketSize, Charset.GetCharset(options.Charset));

            connection.Connect();
            connection.Identify(options.Database);

            switch (connection.ProtocolVersion)
            {
            case IscCodes.PROTOCOL_VERSION12:
                return(new FirebirdSql.Data.Client.Managed.Version12.GdsDatabase(connection));

            case IscCodes.PROTOCOL_VERSION11:
                return(new FirebirdSql.Data.Client.Managed.Version11.GdsDatabase(connection));

            case IscCodes.PROTOCOL_VERSION10:
                return(new FirebirdSql.Data.Client.Managed.Version10.GdsDatabase(connection));

            default:
                throw new NotSupportedException("Protocol not supported.");
            }
        }
        public FbConnectionInternal(FbConnectionString options)
        {
            _preparedCommands = new HashSet <FbCommand>();

            _options = options;
        }
 public void Disconnect()
 {
     if (this.db != null)
     {
         try
         {
             this.db.Dispose();
         }
         catch
         {
         }
         finally
         {
             this.db = null;
             this.owningConnection = null;
             this.options = null;
         }
     }
 }
Exemple #40
0
        public FbConnectionInternal(FbConnectionString options)
        {
            _preparedCommands = new List <WeakReference>();

            _options = options;
        }
		public void Disconnect()
		{
			if (_db != null)
			{
				try
				{
					_db.Dispose();
				}
				catch
				{ }
				finally
				{
					_db = null;
					_owningConnection = null;
					_options = null;
				}
			}
		}
			static FbConnectionInternal CreateNewConnection(FbConnectionString connectionString, FbConnection owner)
			{
				var result = new FbConnectionInternal(connectionString);
				result.SetOwningConnection(owner);
				result.Connect();
				return result;
			}
 public void ParsingWithWhiteSpacesKeyConnectionStringTest()
 {
     const string ConnectionString = "user= \t;password=testpwd";
     var cs = new FbConnectionString(ConnectionString);
     Assert.AreEqual("", cs.UserID);
     Assert.AreEqual("testpwd", cs.Password);
 }
		public void ParsingWithoutEndingSemicolonConnectionStringTest()
		{
			const string ConnectionString = "user=testuser;password=testpwd";
			var cs = new FbConnectionString(ConnectionString);
			Assert.AreEqual("testuser", cs.UserID);
			Assert.AreEqual("testpwd", cs.Password);
		}
		internal FbConnectionInternal Get(FbConnectionString connectionString, FbConnection owner)
		{
			CheckDisposed();

			return _pools.GetOrAdd(connectionString.NormalizedConnectionString, _ => new Pool(connectionString)).GetConnection(owner);
		}
		public void ParsingSpacesInKeyConnectionStringTest()
		{
			const string ConnectionString = "data source=testserver";
			var cs = new FbConnectionString(ConnectionString);
			Assert.AreEqual("testserver", cs.DataSource);
		}
		public void ParsingOneCharValueConnectionStringTest()
		{
			const string ConnectionString = "connection lifetime=6";
			var cs = new FbConnectionString(ConnectionString);
			Assert.AreEqual(6, cs.ConnectionLifeTime);
		}
		public void ParsingDoubleQuotedConnectionStringTest()
		{
			const string ConnectionString = "datasource=testserver;database=testdb.fdb;user=testuser;password=test\"pwd";
			var cs = new FbConnectionString(ConnectionString);
			Assert.AreEqual("test\"pwd", cs.Password);
		}
		public FbConnectionInternal(FbConnectionString options)
		{
			_preparedCommands = new List<WeakReference>();
			_preparedCommandsCleanupSyncRoot = new object();

			_options = options;
		}
		public FbConnectionPool(string connectionString)
		{
			this.connectionString	= connectionString;
			this.options			= new FbConnectionString(connectionString);
			this.lifeTime			= this.options.ConnectionLifeTime * TimeSpan.TicksPerSecond;

			if (this.options.MaxPoolSize == 0)
			{
				this.locked     = ArrayList.Synchronized(new ArrayList());
				this.unlocked   = ArrayList.Synchronized(new ArrayList());
			}
			else
			{
				this.locked     = ArrayList.Synchronized(new ArrayList(this.options.MaxPoolSize));
				this.unlocked   = ArrayList.Synchronized(new ArrayList(this.options.MaxPoolSize));
			}

			// If a	minimun	number of connections is requested initialize the pool
			this.Initialize();

			// Start the cleanup only if needed
			if (this.lifeTime != 0)
			{
				long interval = Convert.ToInt64(TimeSpan.FromTicks(this.lifeTime).TotalMilliseconds);
				this.cleanupTimer = new Timer(new TimerCallback(this.CleanupWorker), this, interval, interval);
			}
		}
		internal void ClearPool(FbConnectionString connectionString)
		{
			CheckDisposed();

			var pool = default(Pool);
			if (_pools.TryGetValue(connectionString.NormalizedConnectionString, out pool))
			{
				pool.ClearPool();
			}
		}
        public static void DropDatabase(string connectionString)
        {
            // Configure Attachment
            FbConnectionString options = new FbConnectionString(connectionString);
            options.Validate();

            try
            {
                // Drop	the	database	
                FbConnectionInternal db = new FbConnectionInternal(options);
                db.DropDatabase();
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Exemple #53
0
        internal FbConnectionInternal Get(FbConnectionString connectionString, FbConnection owner)
        {
            CheckDisposed();

            return(_pools.GetOrAdd(connectionString.NormalizedConnectionString, _ => new Pool(connectionString)).GetConnection(owner));
        }
        protected override void Dispose(bool disposing)
        {
            lock (this)
            {
                if (!this.disposed)
                {
                    try
                    {
                        // release any unmanaged resources
                        this.Close();

                        if (disposing)
                        {
                            // release any managed resources
                            this.innerConnection = null;
                            this.options = null;
                            this.connectionString = null;
                        }

                        this.disposed = true;
                    }
                    catch
                    {
                    }
                    finally
                    {
                        base.Dispose(disposing);
                    }
                }
            }
        }
			FbConnectionInternal CreateNewConnectionIfPossibleImpl(FbConnectionString connectionString, FbConnection owner)
			{
				if (_busy.Count() + 1 > connectionString.MaxPoolSize)
					throw new InvalidOperationException("Connection pool is full.");
				return CreateNewConnection(connectionString, owner);
			}
        public static void CreateDatabase(string connectionString, int pageSize, bool forcedWrites, bool overwrite)
        {
            FbConnectionString options = new FbConnectionString(connectionString);
            options.Validate();

            try
            {
                // DPB configuration
                DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

                // Dpb version
                dpb.Append(IscCodes.isc_dpb_version1);

                // Dummy packet	interval
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });

                // User	name
                dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);

                // User	password
                dpb.Append(IscCodes.isc_dpb_password, options.Password);

                // Database	dialect
                dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });

                // Character set
                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);
                    }
                }

                // Forced writes
                dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0));

                // Database overwrite
                dpb.Append(IscCodes.isc_dpb_overwrite, (overwrite ? 1 : 0));

                // Page	Size
                if (pageSize > 0)
                {
                    dpb.Append(IscCodes.isc_dpb_page_size, pageSize);
                }

                // Create the new database
                FbConnectionInternal db = new FbConnectionInternal(options);
                db.CreateDatabase(dpb);
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
        private DatabaseParameterBuffer BuildDpb(IDatabase db, FbConnectionString options)
        {
            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[] { Convert.ToByte(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.Role))
            {
                dpb.Append(IscCodes.isc_dpb_sql_role_name, options.Role);
            }
            dpb.Append(IscCodes.isc_dpb_connect_timeout, options.ConnectionTimeout);

            if (!options.FallIntoTrustedAuth)
            {
                dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);
                dpb.Append(IscCodes.isc_dpb_password, options.Password);
            }
            dpb.Append(IscCodes.isc_dpb_process_id, GetProcessId());
            dpb.Append(IscCodes.isc_dpb_process_name, GetProcessName());
            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;
        }
		public FbConnection(string connectionString)
			: base()
		{
			_options = new FbConnectionString();
			_state = ConnectionState.Closed;
			_connectionString = string.Empty;

			if (!string.IsNullOrEmpty(connectionString))
			{
				ConnectionString = connectionString;
			}
		}
			public void Dispose()
			{
				lock (_syncRoot)
				{
					if (_disposed)
						return;
					_disposed = true;
					_connectionString = null;
					CleanConnectionsImpl();
					_available = null;
					_busy = null;
				}
			}
        private static IServiceManager CreateManagedServiceManager(FbConnectionString options)
        {
            FirebirdSql.Data.Client.Managed.Version10.GdsConnection connection = new FirebirdSql.Data.Client.Managed.Version10.GdsConnection(options.DataSource, options.Port, options.PacketSize, Charset.GetCharset(options.Charset));

            connection.Connect();
            connection.Identify(!string.IsNullOrEmpty(options.Database) ? options.Database : string.Empty);

            switch (connection.ProtocolVersion)
            {
                case IscCodes.PROTOCOL_VERSION12:
                case IscCodes.PROTOCOL_VERSION11:
                case IscCodes.PROTOCOL_VERSION10:
                    return new FirebirdSql.Data.Client.Managed.Version10.GdsServiceManager(connection);
                default:
                    throw new NotSupportedException("Protocol not supported.");
            }
        }