Example #1
0
        public FbConnectionPool(string connectionString)
        {
            this.syncObject       = new object();
            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 thread	only if	needed
            if (this.lifeTime != 0)
            {
                this.isRunning = true;

                this.cleanUpThread      = new Thread(new ThreadStart(this.RunCleanup));
                this.cleanUpThread.Name = "Cleanup Thread";
                this.cleanUpThread.Start();
                this.cleanUpThread.IsBackground = true;
            }
        }
Example #2
0
        /// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/constructor[@name="ctor(System.String)"]/*'/>
        public FbConnection(string connectionString) : base()
        {
            this.options          = new FbConnectionString();
            this.state            = ConnectionState.Closed;
            this.connectionString = "";

            if (connectionString != null)
            {
                this.ConnectionString = connectionString;
            }
        }
Example #3
0
        public static void DropDatabase(Hashtable values)
        {
            int serverType = 0;

            if (!values.ContainsKey("User") ||
                !values.ContainsKey("Password") ||
                !values.ContainsKey("Database"))
            {
                throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
            }

            if (!values.ContainsKey("DataSource"))
            {
                values.Add("DataSource", "localhost");
            }

            if (!values.ContainsKey("Port"))
            {
                values.Add("Port", 3050);
            }

            if (values.ContainsKey("ServerType"))
            {
                serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
            }

            try
            {
                // Configure Attachment
                FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

                csb.DataSource = values["DataSource"].ToString();
                csb.Port       = Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
                csb.Database   = values["Database"].ToString();
                csb.UserID     = values["User"].ToString();
                csb.Password   = values["Password"].ToString();
                csb.ServerType = serverType;

                FbConnectionString options = new FbConnectionString(csb);

                // Drop	the	database
                FbConnectionInternal db = new FbConnectionInternal(options);
                db.DropDatabase();
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Example #4
0
        /// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="DropDatabase(System.String)"]/*'/>
        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);
            }
        }
Example #5
0
        public void Disconnect()
        {
            try
            {
                this.db.Dispose();

                this.owningConnection = null;
                this.options          = null;
                this.lifetime         = 0;
                this.pooled           = false;
                this.db = null;

                this.DisposePreparedCommands();
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Example #6
0
        private DatabaseParameterBuffer BuildDpb(IDatabase db, FbConnectionString options)
        {
            DatabaseParameterBuffer dpb = db.CreateDatabaseParameterBuffer();

            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.Role != null && options.Role.Length > 0)
            {
                dpb.Append(IscCodes.isc_dpb_sql_role_name, options.Role);
            }
            dpb.Append(IscCodes.isc_dpb_connect_timeout, options.ConnectionTimeout);
            dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);
            dpb.Append(IscCodes.isc_dpb_password, options.Password);

            return(dpb);
        }
		public FbConnectionInternal(FbConnectionString options, FbConnection owningConnection)
		{
			this.options = options;
			this.owningConnection = owningConnection;
		}
		public FbConnectionInternal(FbConnectionString options) : this(options, null)
		{
		}
		public FbConnectionPool(string connectionString)
		{
			this.syncObject			= new object();
			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 thread	only if	needed
			if (this.lifeTime != 0)
			{
				this.isRunning = true;

				this.cleanUpThread = new Thread(new ThreadStart(this.RunCleanup));
				this.cleanUpThread.Name = "Cleanup Thread";
				this.cleanUpThread.Start();
				this.cleanUpThread.IsBackground = true;
			}
		}
		public static void DropDatabase(Hashtable values)
		{
			int serverType = 0;

			if (!values.ContainsKey("User") ||
				!values.ContainsKey("Password") ||
				!values.ContainsKey("Database"))
			{
				throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
			}

			if (!values.ContainsKey("DataSource"))
			{
				values.Add("DataSource", "localhost");
			}

			if (!values.ContainsKey("Port"))
			{
				values.Add("Port", 3050);
			}

			if (values.ContainsKey("ServerType"))
			{
				serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
			}

			try
			{
				// Configure Attachment
				FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

				csb.DataSource = values["DataSource"].ToString();
				csb.Port = Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
				csb.Database = values["Database"].ToString();
				csb.UserID = values["User"].ToString();
				csb.Password = values["Password"].ToString();
				csb.ServerType = serverType;

				FbConnectionString options = new FbConnectionString(csb);

				// Drop	the	database
				FbConnectionInternal db = new FbConnectionInternal(options);
				db.DropDatabase();
			}
			catch (IscException ex)
			{
				throw new FbException(ex.Message, ex);
			}
		}
		public static void CreateDatabase(Hashtable values)
		{
			bool overwrite = false;
			int index = 0;
			byte dialect = 3;
			int serverType = 0;

			if (!values.ContainsKey("User") ||
				!values.ContainsKey("Password") ||
				!values.ContainsKey("Database"))
			{
				throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
			}

			if (values.ContainsKey("ServerType"))
			{
				serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
			}

			if (!values.ContainsKey("DataSource"))
			{
				values.Add("DataSource", "localhost");
			}

			if (!values.ContainsKey("Port"))
			{
				values.Add("Port", 3050);
			}

			if (values.ContainsKey("Dialect"))
			{
				dialect = Convert.ToByte(values["Dialect"], CultureInfo.InvariantCulture);
			}

			if (dialect < 1 || dialect > 3)
			{
				throw new ArgumentException("Incorrect database dialect it should be 1, 2, or 3.");
			}

			if (values.ContainsKey("Overwrite"))
			{
				overwrite = (bool)values["Overwrite"];
			}

			try
			{
				// Configure Attachment
				FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

				csb.DataSource	= values["DataSource"].ToString();
				csb.UserID		= values["User"].ToString();
				csb.Password	= values["Password"].ToString();
				csb.Database	= values["Database"].ToString();
				csb.Port		= Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
				csb.ServerType	= serverType;

				FbConnectionString options = new FbConnectionString(csb);

				// 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, values["User"].ToString());

				// User	password
				dpb.Append(IscCodes.isc_dpb_password, values["Password"].ToString());

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

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

				// Character set
				if (values.ContainsKey("Charset"))
				{
					index = Charset.SupportedCharsets.IndexOf(values["Charset"].ToString());

					if (index == -1)
					{
						throw new ArgumentException("Character set is not valid.");
					}
					else
					{
						dpb.Append(
							IscCodes.isc_dpb_set_db_charset,
							Charset.SupportedCharsets[index].Name);
					}
				}

				// Page	Size
				if (values.ContainsKey("PageSize"))
				{
					dpb.Append(IscCodes.isc_dpb_page_size, Convert.ToInt32(values["PageSize"], CultureInfo.InvariantCulture));
				}

				// Forced writes
				if (values.ContainsKey("ForcedWrite"))
				{
					dpb.Append(IscCodes.isc_dpb_force_write,
						(short)((bool)values["ForcedWrite"] ? 1 : 0));
				}

				if (!overwrite)
				{
					try
					{
						// Check if	the	database exists
						FbConnectionInternal check = new FbConnectionInternal(options);

						check.Connect();
						check.Disconnect();

						IscException ex = new IscException(IscCodes.isc_db_or_file_exists);

						throw new FbException(ex.Message, ex);
					}
					catch (Exception)
					{
						throw;
					}
				}

				// Create the new database
				FbConnectionInternal c = new FbConnectionInternal(options);
				c.CreateDatabase(dpb);
			}
			catch (IscException ex)
			{
				throw new FbException(ex.Message, ex);
			}
		}
		/// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="DropDatabase(System.String)"]/*'/>
		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);
			}
		}
		/// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="CreateDatabase(System.String,System.Int32,System.Boolean,System.Boolean)"]/*'/>
		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 });

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

				// Character set
				if (options.Charset.Length > 0)
				{
					int index = Charset.SupportedCharsets.IndexOf(options.Charset);

					if (index == -1)
					{
						throw new ArgumentException("Character set is not valid.");
					}
					else
					{
						dpb.Append(
							IscCodes.isc_dpb_set_db_charset,
							Charset.SupportedCharsets[index].Name);
					}
				}

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

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

				if (!overwrite)
				{
					// Check if	the	database exists
					FbConnectionInternal c = new FbConnectionInternal(options);

					try
					{
						c.Connect();
						c.Disconnect();

						IscException ex = new IscException(IscCodes.isc_db_or_file_exists);
						throw new FbException(ex.Message, ex);
					}
					catch (FbException ex)
					{
						if (ex.ErrorCode != 335544344)
						{
							throw;
						}
					}
				}

				// Create the new database
				FbConnectionInternal db = new FbConnectionInternal(options);
				db.CreateDatabase(dpb);
			}
			catch (IscException ex)
			{
				throw new FbException(ex.Message, ex);
			}
		}
Example #14
0
        /// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="CreateDatabase(System.String,System.Int32,System.Boolean,System.Boolean)"]/*'/>
        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 });

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

                // Character set
                if (options.Charset.Length > 0)
                {
                    int index = Charset.SupportedCharsets.IndexOf(options.Charset);

                    if (index == -1)
                    {
                        throw new ArgumentException("Character set is not valid.");
                    }
                    else
                    {
                        dpb.Append(
                            IscCodes.isc_dpb_set_db_charset,
                            Charset.SupportedCharsets[index].Name);
                    }
                }

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

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

                if (!overwrite)
                {
                    // Check if	the	database exists
                    FbConnectionInternal c = new FbConnectionInternal(options);

                    try
                    {
                        c.Connect();
                        c.Disconnect();

                        IscException ex = new IscException(IscCodes.isc_db_or_file_exists);
                        throw new FbException(ex.Message, ex);
                    }
                    catch (FbException ex)
                    {
                        if (ex.ErrorCode != 335544344)
                        {
                            throw;
                        }
                    }
                }

                // Create the new database
                FbConnectionInternal db = new FbConnectionInternal(options);
                db.CreateDatabase(dpb);
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
		public void Disconnect()
		{
			try
			{
				this.db.Dispose();

				this.owningConnection	= null;
				this.options			= null;
				this.lifetime			= 0;
				this.pooled				= false;
				this.db					= null;

				this.DisposePreparedCommands();
			}
			catch (IscException ex)
			{
				throw new FbException(ex.Message, ex);
			}
		}
Example #16
0
 public FbConnectionInternal(FbConnectionString options, FbConnection owningConnection)
 {
     this.options          = options;
     this.owningConnection = owningConnection;
 }
Example #17
0
 public FbConnectionInternal(FbConnectionString options) : this(options, null)
 {
 }
Example #18
0
        public static void CreateDatabase(Hashtable values)
        {
            bool overwrite  = false;
            int  index      = 0;
            byte dialect    = 3;
            int  serverType = 0;

            if (!values.ContainsKey("User") ||
                !values.ContainsKey("Password") ||
                !values.ContainsKey("Database"))
            {
                throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
            }

            if (values.ContainsKey("ServerType"))
            {
                serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
            }

            if (!values.ContainsKey("DataSource"))
            {
                values.Add("DataSource", "localhost");
            }

            if (!values.ContainsKey("Port"))
            {
                values.Add("Port", 3050);
            }

            if (values.ContainsKey("Dialect"))
            {
                dialect = Convert.ToByte(values["Dialect"], CultureInfo.InvariantCulture);
            }

            if (dialect < 1 || dialect > 3)
            {
                throw new ArgumentException("Incorrect database dialect it should be 1, 2, or 3.");
            }

            if (values.ContainsKey("Overwrite"))
            {
                overwrite = (bool)values["Overwrite"];
            }

            try
            {
                // Configure Attachment
                FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

                csb.DataSource = values["DataSource"].ToString();
                csb.UserID     = values["User"].ToString();
                csb.Password   = values["Password"].ToString();
                csb.Database   = values["Database"].ToString();
                csb.Port       = Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
                csb.ServerType = serverType;

                FbConnectionString options = new FbConnectionString(csb);

                // 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, values["User"].ToString());

                // User	password
                dpb.Append(IscCodes.isc_dpb_password, values["Password"].ToString());

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

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

                // Character set
                if (values.ContainsKey("Charset"))
                {
                    index = Charset.SupportedCharsets.IndexOf(values["Charset"].ToString());

                    if (index == -1)
                    {
                        throw new ArgumentException("Character set is not valid.");
                    }
                    else
                    {
                        dpb.Append(
                            IscCodes.isc_dpb_set_db_charset,
                            Charset.SupportedCharsets[index].Name);
                    }
                }

                // Page	Size
                if (values.ContainsKey("PageSize"))
                {
                    dpb.Append(IscCodes.isc_dpb_page_size, Convert.ToInt32(values["PageSize"], CultureInfo.InvariantCulture));
                }

                // Forced writes
                if (values.ContainsKey("ForcedWrite"))
                {
                    dpb.Append(IscCodes.isc_dpb_force_write,
                               (short)((bool)values["ForcedWrite"] ? 1 : 0));
                }

                if (!overwrite)
                {
                    try
                    {
                        // Check if	the	database exists
                        FbConnectionInternal check = new FbConnectionInternal(options);

                        check.Connect();
                        check.Disconnect();

                        IscException ex = new IscException(IscCodes.isc_db_or_file_exists);

                        throw new FbException(ex.Message, ex);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                // Create the new database
                FbConnectionInternal c = new FbConnectionInternal(options);
                c.CreateDatabase(dpb);
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
		private DatabaseParameterBuffer BuildDpb(IDatabase db, FbConnectionString options)
		{
			DatabaseParameterBuffer dpb = db.CreateDatabaseParameterBuffer();

			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.Role != null && options.Role.Length > 0)
			{
				dpb.Append(IscCodes.isc_dpb_sql_role_name, options.Role);
			}
			dpb.Append(IscCodes.isc_dpb_connect_timeout, options.ConnectionTimeout);
			dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);
			dpb.Append(IscCodes.isc_dpb_password, options.Password);

			return dpb;
		}
		/// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/constructor[@name="ctor(System.String)"]/*'/>	
		public FbConnection(string connectionString) : base()
		{
			this.options = new FbConnectionString();
			this.state = ConnectionState.Closed;
			this.connectionString = "";

			if (connectionString != null)
			{
				this.ConnectionString = connectionString;
			}
		}